PDA

View Full Version : Date script almost works - just need to ignore time of day


Gary Williams
03-25-2003, 09:47 AM
Hi All,

The following script tests 2 dates. If 'today' is earlier than 'coverdate', all is fine. If 'today' is later than 'coverdate', the alert correctly displays.

Here's the problem. If 'today' and 'coverdate' are the same (which is OK), the alert displays because 'today', taken from the system clock, assumes midnight as the starting point (therefore 10am is 'later'). How can I get the script to work with just the date and ignore the time of day?

Regards

Gary

===================

today = new Date();
coverdate = new Date(frmquotation.testcoverdate.value);
gettoday = today.getTime();
getcoverdate = coverdate.getTime();
datetest = gettoday - getcoverdate
if(datetest > 0){
alert("Please choose a cover date from tomorrow onwards.");
frmquotation.cbocoverdateday.focus();
return false;
}

===================

ps. Thanks Justame for the script.

Weirdan
03-25-2003, 11:38 AM
Fill hours:min:sec:millisec fields of date objects with zeroes before comparison:

today.setHours(0,0,0,0);
coverdate.setHours(0,0,0,0);
gettoday = today.getTime();
getcoverdate = coverdate.getTime();
datetest = gettoday - getcoverdate;

save dates in temp variables if you need this values later.

Gary Williams
03-25-2003, 12:34 PM
Thanks Weirdan, worked a treat!

These fixes look so simple when someone else shows you how. I didn't think to set the values to zero.

Regards

Gary