compare two string dates in javascript

This post is show you compare two string dates in javascript. In this post we show you two different method for compare two string dates in javascript.

var date_a =  new Date("03-05-2015").getTime()

var date_b =  new Date("28-04-2016").getTime();

if(date_a > date_b )
{
alert(date_a+" is max date ");
}
elseif(date_a == date_b)
{
alert(" Both date is Equal. ");
}
else
{
alert(date_b+" is max date ");
}

// Or try  this

var date_a = Date.parse("2012-11-01");
var date_b = Date.parse("2012-11-04");

if(date_a > date_b )
{
alert(date_a+" is max date ");
}
elseif(date_a == date_b)
{
alert(" Both date is Equal. ");
}
else
{
alert(date_b+" is max date ");
}

Leave a Comment

Your email address will not be published. Required fields are marked *

9  +    =  12

We're accepting well-written guest posts and this is a great opportunity to collaborate : Contact US