Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Javascript Date/Countdown problem - please help 1

Status
Not open for further replies.

desktopdoodle

Programmer
Jan 8, 2008
1
Hi,

I have a bit of simple code which serves to display the current date and also a countdown to Jan 31st and is to remind people to file their tax returns. Here is the code:

<DIV align=center><H1><SCRIPT language=javascript>
<!--
Today = new Date();
TodayYear = Today.getYear();
if (TodayYear < 2000) TodayYear += 1900;
DateToFind = new Date("January 31, " + TodayYear); difference = DateToFind.getTime() - Today.getTime(); difference = Math.floor(difference / (1000 * 60 * 60 * 24)) + 1;

note = "<br> Call us NOW - <strong> 01452 527 000</strong>"; note2 = "Today is "; note3 = "<br><strong>Just ";
if (difference < 0) { difference = 365 - difference; TodayYear = TodayYear + 1; note = " +/-1"; }

document.write(note2 + Today + note3 + difference + " days</strong> from the deadline for filing your tax return " + note);

--> </SCRIPT></H1></DIV>

The code works fine, in that it shows the date and it counts down. The problem is that it displays the date in long format, like this:

Tue Jan 08 2008 11:43:02 GMT+0000 (GMT Standard Time)

How can I edit it so that it only shows up Tuesday, January 8th, 2008 - without the time/GMT etc?

Any help would be greatly appreciated as I'm rather new to javascript. I have tried searching everywhere and can't find anything anywhere to help me change the date display.

Can anyone help?

Many thanks in advance

Mike B
 
You have to extract the information from the date object and build your own custom date string. This is done using the date methods. You can extract the year, month, date, etc. from the object and put it back together in a new string to display exactly how you want it.

You'll find everything you need here


-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top