I'm searching a way to find the time difference between 2 dates using moment js in seconds only. I want to compare current date with dates that I'm reading from the database.
For example:
//current time
var current_time= moment().format('YYYY-MM-DD HH:mm:ss');
//date from sql query
var starting_date=moment(element.start_date).format('YYYY-MM-DD HH:mm:ss');
// print the dates as they are now
console.log(current_time);
console.log(starting_date);
result:
2019-07-02 18:00:11
2019-05-03 15:59:29
I want to find the difference between these 2 dates in seconds only.
I try to make it work using something like this example i found:
var a = moment([2007, 0, 29]);
var b = moment([2007, 0, 28]);
a.diff(b, 'days')
but it doesn't worked...
var current_time= moment().format('YYYY-MM-DD HH:mm:ss');
var starting_date=moment(element.start_date).format('YYYY-MM-DD HH:mm:ss');
current_time.diff(starting_date, 'seconds');
it crashes
Any idea how to achieve this?