...

View Full Version : get month



hedbanger
07-24-2002, 05:08 AM
my script is getting the wrong month. it should be july. what am i doing wrong? thanks.


<script language="JavaScript">
now = new Date();
month = now.getMonth();
date = now.getDate();
year = now.getYear();
document.write("<font face='arial' size='1' color='#999999'><b>");
document.write("LAST MODIFIED ON ");
document.write("</b></font>");
document.write("<font face='arial' size='1' color='#999999'><b>");
document.write(month + "/" + date + "/" + year);
document.write("</b></font>");
</script>

jkd
07-24-2002, 05:26 AM
The months it returns are I believe from 0-11, not 1-12...

var date = new Date();
var dateString = date.getMonth() + 1 + '/' + date.getDate() + '/' + date.getFullYear().toString().substr(2);

That generates the date string you want...

hedbanger
07-24-2002, 08:15 PM
i know that the months are 0 through 11 but i wonder what i was doing that would cause it to not increment it correctly.
oh well!
what you gave me works, thanks!
(good luck getting a summer job.)

corrected script:
<script language="JavaScript">
var date = new Date();
var dateString = date.getMonth() + 1 + '/' + date.getDate() + '/' + date.getFullYear().toString().substr(2);
document.write("<font face='arial' size='1' color='#999999'><b>");
document.write("LAST MODIFIED ON ");
document.write("</b></font>");
document.write("<font face='arial' size='1' color='#999999'><b>");
document.write(dateString);
document.write("</b></font>");
</script>

hedbanger
07-24-2002, 09:07 PM
oh! i just noticed that you had to increment the month yourself too!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum