Saturday, August 15, 2009

Check if date and time is between two date and times

This javascript code checks whether the checkDate is between beginDate and endDate and generates a MessabeBox



function dateWithin(beginDate,endDate,checkDate) {
var b,e,c;
b = Date.parse(beginDate);
e = Date.parse(endDate);
c = Date.parse(checkDate);
if((c <= e && c >= b)) {
return true;
}
return false;
}

// This will alert 'false'
alert(dateWithin('12/20/2007 12:00:00 AM','12/20/2007 1:00:00 AM','12/19/2007 12:00:00 AM'));




Thanks

Happy Programming.

No comments:

Post a Comment