Forum Moderators: open

Message Too Old, No Replies

adding x days to a date

         

neonpie

2:12 pm on May 12, 2008 (gmt 0)

10+ Year Member



is it possible to take a date and add X days to it?

i have a form that when you click on the input box it displays a calendar (JACS calendar). click the calendar date and it puts that date in the input box. thats great, but i also want it to add say 10 days to that date and add it to another input box.

when it comes to javascript i dont know any syntax

im using:
form.date2.value = parseInt(form.date1.value) + 10;

this would take 15/05/2008 and make it 25 and not 25/05/2008

also i would want it to add it into the next month so on the 25/05/2008 it would add 10 days and become 04/06/2008 (and obviosuly the same at the end of the year)

thanks in advance

Wolf_man

8:17 pm on May 13, 2008 (gmt 0)

10+ Year Member



try this

var x=form.date1.value.split("/"); //split the date by '/'
x=new Date(x[2], (x[0]-1) , x[ 1 ] ); //create a new date object
x.setDate(x.getDate()+10); //increase by 10 days

form.date2.value=x.getMonth()+'/'+x.getDate()+'/'+x.getFullYear();

sfdfsdfsdfsfsdfsdf

[edited by: Wolf_man at 8:31 pm (utc) on May 13, 2008]