Showing posts with label date compare. Show all posts
Showing posts with label date compare. Show all posts

Wednesday, February 4, 2009

Javascript - Compare two Dates

Javascript - Compare two Dates

function CompareDates() {
var txtEffDt = document.getElementById("txtEffectiveDt").value.split("/");
var txtExpDt = document.getElementById("txtExpiryDt").value.split("/");
var date1 = new Date(txtEffDt[2]+'/'+txtEffDt[0]+'/'+txtEffDt[1]);
var date2 = new Date(txtExpDt[2]+'/'+txtExpDt[0]+'/'+txtExpDt[1]);

if (date1 > date2) {
alert("Expiry Date cannot be less than Effective Date");
return false;
}
}