PDA

View Full Version : calculate days between dates


rentacar
01-31-2003, 01:51 PM
Can anyone help a newbie with a form script that will calculate the days between two dates input in a webform by a user? then pass as a field in a form?

Thanks in advance

Gemma

glenngv
01-31-2003, 02:05 PM
function dateDiff(){
to = document.form1.date1.value;
from = document.form1.date2.value;
msec = Date.parse(to)-Date.parse(from);//in milliseconds
//convert msec to days
}

where form1 is the name of the form and date1 and date2 are the date fields.

more info on Date.parse() method:
http://www.devguru.com/Technologies/ecmascript/quickref/date_parse.html