This is just a sanity check, but I’ve done several test cases before you all jump on the “down” button =]
I just want to check that comparing dates from a MySQL database in the format YYYY-MM-DD HH:MM:SS in JavaScript will work correctly. Unfortunately, I can’t edit the query to return a Unix timestamp.
Example:
console.log('2010-05-22 00:54:12' > '2010-05-21 11:44:32');
All my test cases seem to suggest it works fine, but I just need to make sure.
Maybe my Google-fu is weak, but I can’t find anything about it online. Does anyone know for sure?
Yes, I’m sure one reason they chose such a format was so you could do a standard string comparison on them.
Because the order of values is most-significant to least-significant, this will work perfectly fine as long as:
However do note that unless you standardize on a particular time zone (GMT for example), this will only accurately compare dates in a single time zone.