473,387 Members | 1,572 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

javascript to display current date (and back dates)

Hello all,

I've browsed through past usenet archives, but can't seem to come
across quite the javascript I'm looking for. I'm looking for a simple
javascript that will display the date as such:

May 17

So basically, just displaying the current month and the current date.
But I would also like the ability to backdate by one day, two days,
etc.. So the next date might look as such:

May 15

Which would be two days earlier than today's date, but in keeping with
the same format.

Any help on this would be greatly appreciated.
KG
Jul 23 '05 #1
3 2652
In article <d8********************************@4ax.com>, Kevin Gibbons
<kevin@<NOSPAM>kgibbons.com> enlightened us with...
Hello all,

I've browsed through past usenet archives, but can't seem to come
across quite the javascript I'm looking for. I'm looking for a simple
javascript that will display the date as such:

May 17


If you're familiar with java's SimpleDateFormat class, you might like
this author's javascript version.

http://www.mattkruse.com/javascript/date/source.html

--
--
~kaeli~
Reading while sunbathing makes you well red.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 23 '05 #2
Kevin Gibbons <kevin@ wrote:
I'm looking for a simple
javascript that will display the date as such:

May 17

I would also like the ability to backdate by one day, two days,
etc.. So the next date might look as such:

May 15
Any help on this would be greatly appreciated.


m=
["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","S ep","Oct","Nov","Dec"];
n=new Date();
today=m[n.getMonth()] +" "+n.getDate();
alert(today);

n.setDate(n.getDate()-2);
dayBeforeYesterday=m[n.getMonth()]+" " +n.getDate();
alert(dayBeforeYesterday);

Something like that.
Mick
Jul 23 '05 #3
JRS: In article <d8********************************@4ax.com>, seen in
news:comp.lang.javascript, Kevin Gibbons <kevin@?.com> posted at Mon, 17
May 2004 01:12:46 :
I've browsed through past usenet archives, but can't seem to come
across quite the javascript I'm looking for. I'm looking for a simple
javascript that will display the date as such:

May 17
Did you not find the FAQ of this newsgroup?
Did you not find the FAQ of this newsgroup helpful?

So basically, just displaying the current month and the current date.
But I would also like the ability to backdate by one day, two days,
etc.. So the next date might look as such:

May 15


Not a good example; is May the name of the month, or the three-letter
abbreviation therefor? A week earlier, should that be May 5 or May 05 ?

Should the date be local-to-user, local-to-server, or GMT? I assume the
former, and that the user's computer's clock can be believed.

A = ["Jan", "Feb", "Mar", "Apr", "May", ..., "Dec"] // or "January" ..
D = new Date()
ITIS = A[D.getMonth()] + " " + D.getDate()
D.setDate(D.getDate() - 2)
TWAS = A[D.getMonth()] + " " + D.getDate()

That gives May 5 style; for May 05 use LZ(D.getDate()) with

function LZ(x) { return (x<0||x>=10?"":"0") + x }
<FAQENTRY>
IMHO, typing would be saved if LZ were in the FAQ.
</FAQENTRY>
The following can be used for the current date IF you are assured that
the first occurrence of <word> <space> <number> in String(new Date())
will ALWAYS be what you want :-

ITIS = String(new Date()).match(/(\w+ \d+)/)[1]

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://jibbering.com/faq/> Jim Ley's FAQ for news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

34
by: kroger | last post by:
Hi. I am at a loss to decipher why the javascript on my web page: http://www.psych.nmsu.edu/~jkroger/lab/index.html does not display the date correctly in Firefox. Instead of "2005" for the...
19
by: Stimp | last post by:
preferably one that when clicked can update three date dropdowns (day, month, year) like http://www.visitdublin.com/carhire/avis.asp Don't mind paying for the file... anyone seen something...
5
by: settyv | last post by:
Hi, Below is the Javascript function that am trying to call from asp:Button control. <script language="javascript"> function ValidateDate(fromDate,toDate) { var fromDate=new Date();
1
by: xtremebass | last post by:
Hello Bytes, i have a calender program which is created by using Javascript. when i execute that program using Internet Explorer,it works properly but when i tried in Mozilla firefox it didnt...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.