Check if a date is greater with JavaScript

Reading time: less than 1 minute

Check if a date is greater with JavaScript

var dateStart = new Date(2016,06,01);
var dateEnd = new Date(2016,06,03);

var dateStart2 = new Date(2016,06,03);
var dateEnd2 = new Date(2016,06,01);

if(Date.parse(dateStart) < Date.parse(dateEnd)){
    alert("DateStart: "+ dateStart + " is less than " + dateEnd);
}else{
    alert("DateEnd: "+ dateEnd+" is less than "+ dateStart);
}

if(dateStart2 < dateEnd2){
    alert("DateStart: "+ dateStart2 + " is less than " + dateEnd2);
}else{
    alert("DateEnd: "+ dateEnd2+" is less than "+ dateStart2);
}