0

I have two dates in format: Y-m-d H:i:s

How I can calculate time beetweeb two dates:

data.endTime - data.startTime
LaraBeginer
  • 169
  • 1
  • 3
  • 15

1 Answers1

1

The best way is like @Paul S. say, convert them into Date, and then yo can make something like this:

var resultInMs = date_end.getTime() - date_start.getTime();

Hope it works for you.

PD: Here is something that can help you http://www.w3schools.com/jsref/jsref_obj_date.asp

PD2: Like @James Thorpe says Mozilla Docs is also a very good source of information (Even better): https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date

yNeolh
  • 66
  • 7
  • 4
    fyi, the [mozilla docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date) are typically far better than w3schools – James Thorpe Dec 09 '14 at 15:47
  • You can also use integer conversion, i.e. `var resultMs = (+date_end) - (+date_start)` – Paul Dec 09 '14 at 15:49