1

I have two dates startdate and currentdate.

How can I get the difference between the two dates in minutes

console.log("startdate: " + startdate + " currentdate: " + currentdate);
>> startdate: Tue Nov 10 2015 13:00:00 GMT-0800 (PST) 
>> currentdate: Tue Nov 10 2015 11:55:53 GMT-0800 (PST)

console.log(startdate.getTime() - currentdate.getTime());
>> 3846736

I'm able to subtract the two dates, but I'm unsure of how to convert that output (output: 3846736) into minutes.

Onichan
  • 4,476
  • 6
  • 31
  • 60
  • 1
    Possible duplicate of [JavaScript - Get minutes between two dates](http://stackoverflow.com/questions/7709803/javascript-get-minutes-between-two-dates) – Ziki Nov 10 '15 at 20:01

1 Answers1

4

Convert the units:

var milliseconds = (startdate.getTime() - currentDate.getTime());
var seconds = milliseconds / 1000;
var minutes = seconds / 60;

Or, all in one:

var minutes = (startdate.getTime() - currentDate.getTime()) / 1000 / 60;

This will give you a big decimal most likely. For rounding, use Math.floor, Math.ceil, or Math.round.

TbWill4321
  • 8,626
  • 3
  • 27
  • 25