I need to compare two date in javascript.
In my code I am calling a web service method which serialize and returns in JSON format an instance of the following class
public class MyPeriod
{
public int PeriodID { get; set; }
public DateTime BeginDate { get; set; }
public DateTime FirstDeadline { get; set; }
public DateTime SecondDeadline { get; set; }
public DateTime EndDate { get; set; }
}
this will produces a JSON fragment like this:
{
"d": {
"PeriodID":26,
"BeginDate":"\/Date(1321743660000)\/",
"FirstDeadline":"\/Date(1322002860000)\/",
"SecondDeadline":"\/Date(1322002860000)\/",
"EndDate":"\/Date(1322168400000)\/"
}
}
Now I need to compare FirstDeadline
with SecondDeadline
and so in my javascript I have a fragment like this
var date1 = eval(data.d.FirstDeadline.replace(/\/Date\((\d+)\)\//gi, "new Date($1)"));
var date2 = eval(data.d.SecondDeadline.replace(/\/Date\((\d+)\)\//gi, "new Date($1)"));
if (date1 === date2) {
...
}
Unfortunately the equal comparison does not work even if the dates have the same value. Any help?
UPDATE 1
I forgot to mention that I need to compare only the date part (that's way I am not comparing the milliseconds since the epoch).