By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,299 Members | 1,054 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,299 IT Pros & Developers. It's quick & easy.

Trouble With Date Code

P: n/a
Can anyone here help me with this...

I have a date code to display the date 7 days in the future— check it
out here : http://hidefsounds.com/date.html

The problem is that the day of the month doesn't reset when it's past
30/31 days... So currently it shows:

"May 36, 2008."

Any help would be appreciated. Thanks in advance.
Jun 27 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
sixstringsk <th****************@yahoo.comwrites:
I have a date code to display the date 7 days in the future— check it
out here : http://hidefsounds.com/date.html

The problem is that the day of the month doesn't reset when it's past
30/31 days... So currently it shows:

"May 36, 2008."
Use a Date object when you work with dates. It prevents you from
creating non-existing dates by wrapping, e.g., 36th of May into
5th of June.

var d = new Date(); // today
d.setDate(d.getDate()+7); // 7 days later
// format as string before displaying

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jun 27 '08 #2

P: n/a
In comp.lang.javascript message <a1b603ad-f021-4c69-b0ee-57b25e0dd3ae@27
g2000hsf.googlegroups.com>, Thu, 29 May 2008 20:43:48, sixstringsk
<th****************@yahoo.composted:
>Can anyone here help me with this...

I have a date code to display the date 7 days in the future— check it
out here : http://hidefsounds.com/date.html

The problem is that the day of the month doesn't reset when it's past
30/31 days... So currently it shows:

"May 36, 2008."

Any help would be appreciated. Thanks in advance.

Code which is that short should be posted to the newsgroup, for easier
handling.

<QUOTE>
<script language="JavaScript1.2">
// ^^^^^^^^^^^^^^^ Deprecated.
// text/javascript preferred, or nothing.
<!-- Begin
// superfluous
var months=new Array(13);
months[1]="January";
months[2]="February";
months[3]="March";
months[4]="April";
months[5]="May";
months[6]="June";
months[7]="July";
months[8]="August";
months[9]="September";
months[10]="October";
months[11]="November";
months[12]="December";

// var months = ["January", ... "December"] better, and zero-based

var time=new Date();
var lmonth=months[time.getMonth() + 1];
// then no need to add 1
var date=time.getDate() +7;
var year=time.getYear();
if (year < 2000) // Y2K Fix, Isaac Powell
year = year + 1900; // http://onyx.idbsu.edu/~ipowell
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - cannot find
// time.getFullYear() is better
document.write("" + lmonth + " ");
// ^^^^ superfluous
document.write(date + ", " + year + "");
// End -->
// superfluous

</script>
</QUOTE>

Obviously the month will over-range, as you have done nothing to make it
do otherwise.

You should follow Lasse's advice, but ignore the erroneous signature.

Otherwise

It's a good idea to read the newsgroup c.l.j and its FAQ. See below.

--
(c) John Stockton, nr London UK. ?@merlyn.demon.co.uk IE7 FF2 Op9 Sf3
news:comp.lang.javascript FAQ <URL:http://www.jibbering.com/faq/index.html>.
<URL:http://www.merlyn.demon.co.uk/js-index.htmjscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/TP/BP/Delphi/jscr/&c, FAQ items, links.
Jun 27 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.