Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compare two timestamps in this format in javascript?

I have two timestamps formats say,

a='2014-01-15 00:00:00.0'
b='2014-01-16 00:00:00.0'

How to compare and find if b is after a or not?

like image 541
coderman Avatar asked Dec 26 '22 15:12

coderman


2 Answers

You may need to do something like this,

d1 = new Date("2014-01-15 00:00:00.0");
d2 = new Date("2014-01-16 00:00:00.0");

if ((d1 - d2) == 0) {
    alert("equal");
} else if (d1 > d2) {
    alert("d1 > d2");
} else {
    alert("d1 < d2");
}

Working fiddle

like image 54
Deepak Ingole Avatar answered Dec 28 '22 07:12

Deepak Ingole


var a ='2014-01-15 00:00:00.0';
var b ='2014-01-16 00:00:00.0';
if (b > a) {
// do stuff
}
like image 37
felipekm Avatar answered Dec 28 '22 06:12

felipekm