COMPARE - JS

Java on dates

JDate: Date/time

Don't forget to check the documentation for the JDate Class

JS : Computing the difference between two dates, in seconds

const Date1 = Date.parse("2021-01-01 15:13:00");
const Date2 = Date.parse("2021-01-01 15:17:00");

let Diff = (Date1 - Date2)/1000;

JS : Computing the difference between two dates, in hours, with two decimal places

const Date1 = Date.parse("2021-01-01 15:13:00");
const Date2 = Date.parse("2021-01-01 20:17:00");

let result = parseFloat(((Date2 - Date1)/1000/60/60).toFixed(2));
//result = 5.07

Was this article helpful?

Powered by Zendesk