convert string into datetime format in Javascript

dexter picture dexter · Jan 29, 2010 · Viewed 28.3k times · Source

i have a string which, i want to compare with a javascript datetime object. how to convert string "1/1/1912" into datetime using JavaScript so that i can compare like

if (EDateTime > ('1/1/1912'))  {...}

Answer

slashnick picture slashnick · Jan 29, 2010

You could do this simply with a split if you can guarantee the date format.

var dateArray = '1/1/1912'.split("/");
new Date(dateArray[2], dateArray[1], dateArray[0]);