Create a gist now

Instantly share code, notes, and snippets.

const dateDiffInMillis = (date1, date2) =>
Math.abs(date2.getTime() - date1.getTime());
const dayDifferenceInSeconds = (date1, date2) =>
Math.round(dateDiffInMillis(date1, date2) / 1000);
const minuteDifferenceBetweenDates = (date1, date2) =>
Math.round(dayDifferenceInSeconds(date1, date2) / 60);
const hourDifferenceBetweenDates = (date1, date2) =>
Math.round(minuteDifferenceBetweenDates(date1, date2) / 60);
const dayDifferenceBetweenDays = (date1, date2) =>
Math.round(hourDifferenceBetweenDates(date1, date2) / 24);
const formatDate = (date) =>
`${date.getDate()}-${date.getMonth()}-${date.getFullYear()} ` +
`${date.getHours()}:${date.getMinutes()}`;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment