Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check for one date is less than or equal another date in Javascript [duplicate]

I am having a difficult time checking if one date is less than or equal to another.

Here is my code,

var bftStartDt = input1[0]; //This is a string with value "01-Jul-2007"
var bftEndDt = input1[4]; //This is a string with value "01-Jul-1942"

var strtDt = new Date(bftStartDt);
var endDt = new Date(bftEndDt);
var flag = 0; // false

if (endDt <= strtDt){
   flag = 1; // true
}

It never enters the if statement when it should ? What am I missing here.

Thanks

like image 727
AJR Avatar asked Jan 13 '15 21:01

AJR


1 Answers

var strtDt  = new Date("2007-07-01");
var endDt  = new Date("1942-07-01");
var flag = 0; // false

if (endDt <= strtDt){
   flag = 1; // true
   alert("true");
}

It works check out the plunker

like image 157
CognitiveDesire Avatar answered Oct 11 '22 14:10

CognitiveDesire