ASP.NET
ASP.NET

Reputation: 97

how to compare two dates 29-July-2016 and 01-Aug-2016 in angularjs

var startDateValuecmp = 29-July-2016; I have start Date Value in 29-July-2016.

var endDateValuecmp=01-Aug-2016; end Date Value 01-Aug-2016.

I want to compare this formate of date.

if (startDateValuecmp < endDateValuecmp) {
  if (confirm("Please Check Event Date And Follow Up Date!!! Do you want to continue ?") == true) {
    return true;
  } else {
    return false;
  }
}

Upvotes: 0

Views: 71

Answers (2)

shyammakwana.me
shyammakwana.me

Reputation: 5752

You can pass date to Date builtin JavaScript class and then compare it

var startDateValuecmp = new Date('29-July-2016');
var endDateValuecmp  = new Date('01-Aug-2016')

 if ( startDateValuecmp < endDateValuecmp )
 {
...

This will return boolean true or false based on condition.

This will return date in localtime zone, if concern about it use Date.UTC()

Refer this MDN Document.

Update:

This can't be invalid. Press button to Run this code

var startDateValuecmp = new Date('29-July-2016'); 
console.log("startDateValuecmp:", startDateValuecmp);

Upvotes: 1

Thennarasan
Thennarasan

Reputation: 718

Angular can direclty compare data if the input is well formatted.

If they're date object just compare them directly without .getTime() using ng-if

Upvotes: 1

Related Questions