...

View Full Version : Date Script Problem



godkevin
05-25-2006, 07:30 PM
Im trying to get this date script to work but display the DAY at 7 days in the future. So if today is 05-01-06 I want the day to show 05-07-06. Here is the simple code im using.

<script type="text/javascript">

var mydate= new Date()
var theyear=mydate.getFullYear()
var themonth=mydate.getMonth()+1
var thetoday=mydate.getDate()

document.write("Today's date is: ")
document.write(theyear+"/"+themonth+"/"+thetoday)

</script>

I thought I could just change var thetoday=mydate.getDate() and just add +7 to make it var thetoday=mydate.getDate()+7

But for some reason like today is 05-25-06 and the script calculates the date as 05-32-06 when i add the 7 days. Is there a way to get this to automatically go to the next month?

Beagle
05-25-2006, 08:15 PM
var d = new Date();

d.setDate(d.getDate()+7);

will get you what you want.

getDate() just returns an integer. when you add 7 to the integer, you get the mathematically correct answer. 25 + 7 shouldn't equal 1.

godkevin
05-25-2006, 09:16 PM
thanks for the reply, im sorry to ask, what would be the format to put that fix into script? I still new and unsure. Could you paste what you replied i nto the script i showed u? Hope this isnt a bother to u.

Beagle
05-25-2006, 09:44 PM
Don't code much?



<script type="text/javascript">

var mydate= new Date();
mydate.setDate(mydate.getDate() + 7);
var theyear=mydate.getFullYear()
var themonth=mydate.getMonth()+1
var thetoday=mydate.getDate()

document.write("Today's date is: ")
document.write(theyear+"/"+themonth+"/"+thetoday)

</script>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum