Compare two Dates using Javascript

Before we begin this tutorial you might like to check on this.

In the below example I have two date objects. I am using theĀ .getTime() method of the date object to compare these dates and show an alert accordingly.

var firstDate = new Date("2/12/2012");  
var secondDate = new Date("2/12/2012");
// We can use all comparison operators like '=', or less than, greater than operators.  
if (firstDate.getTime() == secondDate.getTime()) {
alert("Both dates are same.");
else {
alert("Different dates.");
Here is a more detailed read.