0

I have to compare if 15 seconds has passed between the first and the second date which I get from JSON in format: 2019-01-31T10:45:10.000Z I try to make something as:

var a = moment(first.date);
var b = moment(second.date);
console.log(a.diff(b, 'seconds'));

But it doesn't work correctly at all. Any suggestions ?

Mamun
  • 66,969
  • 9
  • 47
  • 59
pantofka
  • 13
  • 5
  • 1
    Works fine for me: http://jsfiddle.net/khrismuc/e6zpduor/ How exactly does it fail? What is the output? Any error messages? Etc. –  Apr 15 '19 at 14:25
  • You can check how to do it here: https://stackoverflow.com/questions/22600856/moment-js-date-time-comparison – tarabor Apr 15 '19 at 14:25

1 Answers1

0
Can you be more specific??

let a = moment('2018-10-10 10:50:00');
let b = moment('2018-10-10 10:51:00');

var c = moment('2019-01-31T10:50:00.000Z');
var d = moment('2019-01-31T10:51:00.000Z');

console.log(a);
console.log(b);
console.log(b.diff(a, 'seconds'));

console.log(c);
console.log(d);
console.log(d.diff(c, 'seconds'));

// outputs
moment("2018-10-10T10:50:00.000")
moment("2018-10-10T10:51:00.000")
60

moment("2019-01-31T10:50:00.000")
moment("2019-01-31T10:51:00.000")
60