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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Arnab MukherjeePosted Jan 18, 2022, 7:21 AM
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));