I have two variables formated like this
2017-09-27 16:26:39
2017-09-28 06:30:00
I have two variables formated like this
2017-09-27 16:26:39
2017-09-28 06:30:00
You could use Date.parse
to convert your variables to unix timestamps. Then you could compare the two timestamps like as follows.
var unixtimeOne = Date.parse("2017-09-27 16:26:39");
var unixtimeTwo = Date.parse("2017-09-28 06:30:00");
console.log(unixtimeOne);
console.log(unixtimeTwo);
// You could compare the timestamps as follows
console.log(unixtimeOne < unixtimeTwo)
var date1 = new Date('2017 09-27 16:26:39');
var date2 = new Date('2017-09-28 06:30:00');
var msecs1 = date1.getTime(); // in milliseconds
var msecs2 = date2.getTime(); // in milliseconds
console.log(msecs1 - msecs2); // -50601000
If you are willing to use moment.js, it gives you great comparison methods such as 'isSame', 'isAfter' and 'isBefore':
var x = moment('2017-09-27 16:26:39');
var y = moment('2017-09-28 06:30:00');
x.isSame(y) //false
x.isAfter(y) //false
x.isBefore(y) //true
To find the time difference between the two datetimes:
y.diff(x, 'hours') //14