Javascript: compare dates

// Check dates; format dd-mm-YYYY
var startDate = $("#startDate").val();
var endDate = $("#endDate").val();
 
startDate = startDate.split('-');
endDate = endDate.split('-');
 
startDate = new Date(startDate[2], startDate[1], startDate[0]);
endDate = new Date(endDate[2], endDate[1], endDate[0]);
 
if (startDate > endDate) {
  alert('Error: the enddate cannot be sooner than the startdate');
}

Leave a Reply