Skip to content

Instantly share code, notes, and snippets.

View iamsainikhil's full-sized avatar
👨‍💻
A good developer is always learning…

Sai Nikhil iamsainikhil

👨‍💻
A good developer is always learning…
View GitHub Profile
@iamsainikhil
iamsainikhil / dateDifference.ts
Last active August 23, 2020 04:44
To calculate the difference between two dates in Years, Months, Days, Hours, Minutes, Seconds, Milliseconds using JavaScript / TypeScript
dateDifference(actualDate, value: boolean) {
// Calculate time between two dates:
const date1 = actualDate; // the date you already commented/ posted
const date2: any = new Date(); // today
let r = {}; // object for clarity
let message: string;
const diffInSeconds: number = Math.abs(date2 - date1) / 1000;
const days: number = Math.floor(diffInSeconds / 60 / 60 / 24);