0

Refferred Date difference in hours - Angular 2, which was not returns

let creationDate =params.data.createdTime;
let incidentDate= params.data.incidentTime;
let diffInMs = Date.parse(creationDate) - Date.parse(incidentDate);
let diffInHours = diffInMs / 1000 / 60 / 60;

Which return wrong anwers or in most case NaN,

Date is in this format - `08/03/2017 10:52:58 AM - 06/03/2017 10:48:15 PM`

DATEFORMAT : dd/MM/yyyy hh:mm:ss a

Community
  • 1
  • 1
Rosh
  • 1,676
  • 4
  • 21
  • 35
  • You sure you're subtracting the latest date from the earliest date to ensure that you're getting a positive number? Also, can you be sure that the values you're getting can be parsed unambiguously (like ISO 8601)? – Makoto Mar 09 '17 at 06:43
  • You sure you're subtracting the latest date from the earliest date to ensure that you're getting a positive number? - yes made sure this. 2) I didnt get this point Also, can you be sure that the values you're getting can be parsed unambiguously (like ISO 8601)? – Rosh Mar 09 '17 at 06:49
  • 2
    I don't see how this is related to angular js at all. Check moment.js library – Tebe Mar 09 '17 at 07:32
  • Can't we achieve this with out using external plugin – Rosh Mar 09 '17 at 07:34
  • Looks like a dup of http://stackoverflow.com/questions/7763327/how-to-calculate-date-difference-in-javascript – Günter Zöchbauer Mar 09 '17 at 07:36
  • @Günter Zöchbauer That is just on date, its of date time stamp – Rosh Mar 09 '17 at 08:00

0 Answers0