What you are doing is text comparison. This will work provided you append "0" to month and day portion
(if month or day is less than 9).
Or
You can use Date object and Date arithematics to efficient comparison
function DateComare (date1Str, date2Str) {
var date1 = new Date(date1Str);
var date2 = new Date(date2Str);
//
if (date1 < date2)
{
alert ("Date1 is greater ");
}
else if (date1 > date2)
{
alert ("Date2 is greater ");
}
else {
alert ("Same Dates");
}
}
Main Topics
Browse All Topics





by: ThogekPosted on 2005-08-24 at 21:04:48ID: 14749067
Note that the text-box's value property is a string, so the results you are getting are correct, when you realize that you're doing string (not date) comparisons.
tDate.valu e) > new Date(document.frmTest.endD ate.value) ){
You could try something like:
if ( new Date(document.frmTest.star
alert ("Start Date is greater");
}