javascript to display current date (and back dates)

K

Kevin Gibbons

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
 
D

Dr John Stockton

JRS: In article <[email protected]>, seen in
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]
 
M

Mick White

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","Sep","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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top