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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking for later enddate after startdate 1

Status
Not open for further replies.

oaklandar

Technical User
Feb 12, 2004
246
0
0
US
I am trying to validate my StartDate and EndDate entries in my form. I want to make sure EndDate entry is later than the StartDate entry. The below works except if someone enters 03/4/04 instead of 03/04/04. Basically any single day entry without a zero in front of it ruins my validation. Please advise of a better validation or how I can get this to work?
Code:
function checkDate()
{
var f = document.forms[0];

	if (f.EndDate.value >= f.StartDate.value) 
	{                              
   		return true;
	}
	else
	{
		alert("End Date must be after Start Date.\n");
		return false;
	}
}
 
This is the code that I used to validate:
Code:
var endDate = new Date(document.Mainform.mydate2.value);
var startDate = new Date(document.Mainform.mydate1.value);
if (startDate > endDate )
 {
 alert("The end date must be after the start date");
 document.Mainform.mydate2.focus();
 }

I am not 100% positive that it is foolproof, but it seems to be working. Let me know if you have any problems. Thanks!
 
Thanks that is what I wanted. Are endDate and StartDate references to the Date class?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top