I need to get no of years falling between two dates in a typescript .
for example : Date1 = '13/12/2020' and Date2 is '01/01/2023'
I want result as 4
I need to get no of years falling between two dates in a typescript .
for example : Date1 = '13/12/2020' and Date2 is '01/01/2023'
I want result as 4
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Arnab MukherjeeRank #879 · 2.5K reputationPosted Jan 18, 2022, 2:21 AM EST
let startDate: string = "2020-01-12";
let enddate:string="2023-11-01";
let date1: Date = new Date(startDate);
let date2: Date = new Date(enddate);
let timeInMilisec: number = date2.getTime() - date1.getTime();
let daysBetweenDates: number = Math.ceil(timeInMilisec / (1000 * 60 * 60 * 24));
console.log(Math.ceil(daysBetweenDates/365));