I have datetimes and dates stored as strings in javscript that I need to compare.
Leaving them as strings seems to work:
const date1 = '2016-01-26 05:20:44'
const date2 = '2016-01-26 06:20:44'
const date3 = '2016-02-26'
date1 > date2 //false
date1 < date2 //true
date3 > date2 //true
date3 > date1 //true
date1 > date3 //false
The question: can I depend on this? Or is this a "it works, but it's not reliable" kind of deal?
Should I convert the date strings into date objects (using date or moment)
date1 > date2should bedate1.localCompare(date2) > 0.