// How many days between two dates
function gDaysBetweenDates(date1, date2) {
var date1_ms = date1.getTime();
var date2_ms = date2.getTime();
return Math.round(Math.abs(date1_ms - date2_ms) / (1000 * 60 * 60 * 24));
}
Date1 and date2 being passed are Date objects with values like:
Tue Mar 09 2010 00:00:00 GMT+0000 (GMT Standard Time)
I get a problem when trying to extract the time, it says getTime is undefined. When I try and create a new date object with the dates passed in via:
var dateNew = new Date(date1);
I get the error, date is in invalid format.
new Date('Tue Mar 09 2010 00:00:00 GMT+0000 (GMT Standard Time)');
works. Check the values passed are notundefined
(or anything else for that matter) (alert
them insidegDaysBetweenDates
) – Matt