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!

Validate Start Date and Start Time with End Date & End Time

Status
Not open for further replies.

venomdesign

Programmer
Apr 6, 2001
18
US
Is there a way to validate a start date & start time, to a end date & end time to make sure the end ing is not before the start. One field will be for the start date and the another for the start time then validated against a field for end date and another for end time. It is for use with auction functionality. Any help would be greatfull.
 
This will validate date1 is after date2, you can modify this to incorporate the time element also.

var cdate1, cdate2, day1, day2, mon1, mon2, year1, year2
cdate1="27/07/01" //replaceable with document.formname.fieldname1.value
cdate2="26/07/01" //replaceable with document.formname.fieldname2.value
day1 = cdate1.slice(0,2)
mon1 = cdate1.slice(3,5)
year1 = cdate1.slice(6,8)

day2 = cdate2.slice(0,2)
mon2 = cdate2.slice(3,5)
year2 = cdate2.slice(6,8)

if ( (year1 > year2) || ((year1 >= year2) && (mon1 > mon2)) || ((year1 >= year2) && (mon1 >= mon2) && (day1 > day2)) )
{
alert("The start date '" + day1+"/"+mon1+"/"+year1 + "' is after the end date '" + day2+"/"+mon2+"/"+year2 + "'.\nPlease confirm and re-enter date values")
// return
}


Hope this helps you on your way. DeltaFlyer
The Only Programmer To Crash With Style. LOL
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top