Difference between two dates in years, months, days
0
I’ve been searching for a solution to get the difference between two dates in years, months and days like 10th of April 2019 was 2 years, 2 months and 11 days ago, or 12th of Juli 2021 was 0 years, 2 months and 12 days ago. (in reference to current date 24/9/21). I know how to get the amount of years, this should be done by calanderYearsBetween(Date1, CurrentDate), the amount of monts should be something like calanderMonths(Date1, CurrentDate) – (12 * amountOfYears). But I can’t think of something to get the amount of days. Is there any option to calcualte something like this, it needs to be exact...
asked
Alexander Roos
3 answers
3
Hi Alexander,
You will need to follow these steps in a microflow: (Assuming Date1 is the earlier date and Date2 is the latter date)
YY= calendarYearsBetween(Date1, Date2)
Date1A=addYears(Date1,YY)
MM=calendarMonthsBetween(Date1A, Date2)
Date1C=addMonths(Date1A,MM)
DD= daysBetween(Date1C, Date2)
Your solution is YY years, MM months and DD days
answered
Shekhar Tyagi
1
If you need a calculation between a date in the past and the current date, try out the Formatstring widget which has this feature included with translatable strings.
More info: https://docs.mendix.com/appstore/widgets/format-string#translatable-strings