Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

comparing dates

Status
Not open for further replies.

stemitch2000

Programmer
Nov 12, 2003
47
GB
hello,

I have two text fields containing dates, a start date and a due date. I would like to compare these dates so that the user can not enter a due date that is before the start date.
This is the code I have so far. Any suggestions will be greatly appreciated.

if (new_detail.start.value > new_detail.duedate.value) {
alert("The Due Date can not be before Start Date.");
document.new_detail.duedate.focus();
}
 
Here it's set up in function form. It returns false if the due date comes before the start.
Code:
function checkDates() {
   var startDate = new Date();
   var dueDate = new Date();
   startDate.setTime(Date.parse(new_detail.start.value));
   dueDate.setTime(Date.parse(new_detail.duedate.value));
   if (startDate > dueDate) {
      alert("The Due Date can not be before Start Date.");
      document.new_detail.duedate.focus();
      return false;
   }
   return true;
}

-kaht

banghead.gif
 
FYI, I also had the same problem. Works like a charm.

Thanks
Jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top