var startdate = '02.05.2018 18:05:03';
How to find out how many minutes have passed from startdate to now?
My try
var exp = moment(startdate);
minutes = moment().diff(exp, 'minutes');
but result 124764 it not right
var startdate = '02.05.2018 18:05:03';
How to find out how many minutes have passed from startdate to now?
My try
var exp = moment(startdate);
minutes = moment().diff(exp, 'minutes');
but result 124764 it not right
Share Improve this question asked May 3, 2018 at 7:32 valeravalera 791 gold badge1 silver badge7 bronze badges 02 Answers
Reset to default 6Parsing of date strings are not consistent among browsers. Always pass the format of the string if it is in non-ISO format to prevent unwanted bugs:
var exp = moment(startdate, 'DD.MM.YYYY HH:mm:ss');
moment().diff(exp, 'minutes');
To get the difference between two moment time objects, you can use .diff()
. Then you can use any of asHours()
, asMinutes()
, asSeconds()
to get human-readable time difference.
var start = moment('02.05.2018 18:05:03');
var end = moment('02.05.2018 18:11:03');
var duration = moment.duration(end.diff(start));
var mins = duration.asMinutes();
console.log(mins)
In your case, you can simply call moment().diff(time)
since you want to get difference between the time you specify and now.
var time = moment('02.05.2018 18:05:03');
var duration = moment.duration(moment().diff(time));
var mins = duration.asMinutes();
console.log(mins)