0

I am sending date from frontend like below:

11/26/2018

Now i want to convert it into type Date, So that it can be comparable to any other date.How can i do it in node.js.

3 Answers3

0

This is quite simple:

mydate = new Date("11/26/2018")

See further info here

AJS
  • 1,993
  • 16
  • 26
0

const initialDate="11/26/2018"
let splited = initialDate.split("/");
let date=new Date(splited[2], splited[1] - 1, splited[0])

note that the months are indexed from 0.

Fawzi
  • 359
  • 2
  • 12
0

var mydate = new Date('11/26/18');

var mydate2 = new Date('11/24/18');

console.log('String Format =',mydate.toDateString());
console.log('ISO Format =', mydate.toISOString());

if (mydate > mydate2) {
    console.log('mydate is greater than mydate2');
}else{
    console.log('mydate is less than mydate2');
}

you can also use moment.js

Saurabh Mistry
  • 12,833
  • 5
  • 50
  • 71