sunkiss1
12-15-2006, 02:30 PM
Hi to all,
I have a rather long and complex script that controls the reservations for our vacation homes. Part of the script determines the length of stay by determining the difference between the arrival date and departure date. You can see the reservation form in action at:
http://www.sunkissvillas.com/reservations/disneyluxury/reservations.htm
The entire script works well but I recently discovered that when someone enters an arrival date at the end of March, 2007 and a departure date in April of the next month the number of nights (length of stay) is short by one night. All other months work properly, inlcuding the following year for the same months.
Here is a snippet of the code that determines the length of stay:
<!--Start
//The following sections determines the number of days between the curretn date and the arrival date
function duedateDiff(charges) {
date1 = new Date();
date2 = new Date();
diff = new Date();
if (isValidDate(charges.currentdate.value) && isValidTime(charges.firsttime.value)) { // Validates first date
date1temp = new Date(charges.currentdate.value + " " + charges.firsttime.value);
date1.setTime(date1temp.getTime());
}
else return false; // otherwise exits
if (isValidDate(charges.date8a.value) && isValidTime(charges.secondtime.value)) { // Validates second date
date2temp = new Date(charges.date8a.value + " " + charges.secondtime.value);
date2.setTime(date2temp.getTime());
}
else return false; // otherwise exits
// sets difference date to difference of first date and second date
diff.setTime(Math.abs(date1.getTime() - date2.getTime()));
timediff = diff.getTime();
weeks = Math.floor(timediff / (1000 * 60 * 60 * 24 * 7));
timediff -= weeks * (1000 * 60 * 60 * 24 * 7);
days = Math.floor(timediff / (1000 * 60 * 60 * 24));
timediff -= days * (1000 * 60 * 60 * 24);
hours = Math.floor(timediff / (1000 * 60 * 60));
timediff -= hours * (1000 * 60 * 60);
mins = Math.floor(timediff / (1000 * 60));
timediff -= mins * (1000 * 60);
secs = Math.floor(timediff / 1000);
timediff -= secs * 1000;
charges.duedatedif.value = (weeks * 7) + days ;
return false; // form should never submit, returns false
}
<!--End
You can find the entire code here:
http://www.sunkissvillas.com/JS/FormCalcs6bed.js
This one has me stumped. :confused: Any help or advise is appreciated.
Thanks,
Mark
I have a rather long and complex script that controls the reservations for our vacation homes. Part of the script determines the length of stay by determining the difference between the arrival date and departure date. You can see the reservation form in action at:
http://www.sunkissvillas.com/reservations/disneyluxury/reservations.htm
The entire script works well but I recently discovered that when someone enters an arrival date at the end of March, 2007 and a departure date in April of the next month the number of nights (length of stay) is short by one night. All other months work properly, inlcuding the following year for the same months.
Here is a snippet of the code that determines the length of stay:
<!--Start
//The following sections determines the number of days between the curretn date and the arrival date
function duedateDiff(charges) {
date1 = new Date();
date2 = new Date();
diff = new Date();
if (isValidDate(charges.currentdate.value) && isValidTime(charges.firsttime.value)) { // Validates first date
date1temp = new Date(charges.currentdate.value + " " + charges.firsttime.value);
date1.setTime(date1temp.getTime());
}
else return false; // otherwise exits
if (isValidDate(charges.date8a.value) && isValidTime(charges.secondtime.value)) { // Validates second date
date2temp = new Date(charges.date8a.value + " " + charges.secondtime.value);
date2.setTime(date2temp.getTime());
}
else return false; // otherwise exits
// sets difference date to difference of first date and second date
diff.setTime(Math.abs(date1.getTime() - date2.getTime()));
timediff = diff.getTime();
weeks = Math.floor(timediff / (1000 * 60 * 60 * 24 * 7));
timediff -= weeks * (1000 * 60 * 60 * 24 * 7);
days = Math.floor(timediff / (1000 * 60 * 60 * 24));
timediff -= days * (1000 * 60 * 60 * 24);
hours = Math.floor(timediff / (1000 * 60 * 60));
timediff -= hours * (1000 * 60 * 60);
mins = Math.floor(timediff / (1000 * 60));
timediff -= mins * (1000 * 60);
secs = Math.floor(timediff / 1000);
timediff -= secs * 1000;
charges.duedatedif.value = (weeks * 7) + days ;
return false; // form should never submit, returns false
}
<!--End
You can find the entire code here:
http://www.sunkissvillas.com/JS/FormCalcs6bed.js
This one has me stumped. :confused: Any help or advise is appreciated.
Thanks,
Mark