Shikha thakur Shikha thakur - 2 months ago 9
TypeScript Question

compare dates which gives me wrong result

I need to compare the startDate and endDate and if

startDate>endDate
then i need to take the starting date of the month of endDate as startDate suppose my
startDate is
"startDate": "2016-05-30T00:00:00.000Z"
endDate is
"endDate": "2016-06-05T00:00:00.000Z"
then when compare need to get
true
but i am getting false

Code:

var c=(new Date(nestedObj.startDate)).getDate();
console.log("startdate"+" "+c);
var d=(new Date(nestedObj.endDate)).getDate();
console.log("endtdate"+" "+d);
console.log(c>d);


As you can see in the below snippet

enter image description here

Any help would be appreciated.

Answer

try this

var c = new Date(nestedObj.startDate)
console.log("startdate"+" "+c);
var d=new Date(nestedObj.endDate);
console.log("endtdate"+" "+d);
console.log(c>d);