JackDawkins
Senior member
I really don't know how to write javascript but I can usually take other scripts, modify them, and make things work; but I'm having trouble creating a script that will add a certain number of days to a date and then output the adjusted date.
I have a form that the user selects any date such as this example:
<form name=form1>
<select name=year>
<option>2003</option></select>
<select name=month>
<option value=1>Jan</option></select>
<select name=day>
<option>1</option></select>
<select name=add_days>
<option>3</option></select>
</form>
This is obviously a shortened form, the user has a complete date selection.
Okay, I can pick the values of the date selections no problem using javascript. I can pick the number of days to add also no problem. What I cannot seem to do is take the date of 1 Jan (value=1), 2003 and add 3 days to it.
From what I've seen, I should be doing something like (I've gone ahead and substituted the year, month, day values):
beginDate = new Date(2003, 1, 1);
calcDate = new Date(beginDate.getTime() + 3 * 86400000);
year = calcDate.getYear();
month = calcDate.getMonth();
day = calcDate.getDate();
The real problem I seem to be having is with the javascript date calculation. When I do a calculation for the end of the month, for example, 30 Sept, add 3 days to it, I'll get a return of 1 Oct instead of 3 Oct like it should be. Then if I select any date in the month of December, it will change the year from 2003 to 2004.
I'm stumped. Are there limitations with the javascript Date or getTime functions that I have to take into account? Am I putting in the beginDate values incorrectly by using year, month, day in the new Date function? Or am I coding this just completely wrong? Like I said, I know absolutely nothing about writing javascript so I'm assuming I'm doing something wrong. Any help would be greatly appreciated. Thanks.
Jack
I have a form that the user selects any date such as this example:
<form name=form1>
<select name=year>
<option>2003</option></select>
<select name=month>
<option value=1>Jan</option></select>
<select name=day>
<option>1</option></select>
<select name=add_days>
<option>3</option></select>
</form>
This is obviously a shortened form, the user has a complete date selection.
Okay, I can pick the values of the date selections no problem using javascript. I can pick the number of days to add also no problem. What I cannot seem to do is take the date of 1 Jan (value=1), 2003 and add 3 days to it.
From what I've seen, I should be doing something like (I've gone ahead and substituted the year, month, day values):
beginDate = new Date(2003, 1, 1);
calcDate = new Date(beginDate.getTime() + 3 * 86400000);
year = calcDate.getYear();
month = calcDate.getMonth();
day = calcDate.getDate();
The real problem I seem to be having is with the javascript date calculation. When I do a calculation for the end of the month, for example, 30 Sept, add 3 days to it, I'll get a return of 1 Oct instead of 3 Oct like it should be. Then if I select any date in the month of December, it will change the year from 2003 to 2004.
I'm stumped. Are there limitations with the javascript Date or getTime functions that I have to take into account? Am I putting in the beginDate values incorrectly by using year, month, day in the new Date function? Or am I coding this just completely wrong? Like I said, I know absolutely nothing about writing javascript so I'm assuming I'm doing something wrong. Any help would be greatly appreciated. Thanks.
Jack