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
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)

  1.  YY= calendarYearsBetween(Date1, Date2)
  2. Date1A=addYears(Date1,YY)
  3. MM=calendarMonthsBetween(Date1A, Date2)
  4. Date1C=addMonths(Date1A,MM)
  5.  DD= daysBetween(Date1C, Date2)

 

Your solution is YY years, MM months and DD days

answered
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

answered
0
  1. $DateBegin = Date min
  2. $DateEnd = Date max
  3. $MonthsBetween = calendarMonthsBetween($DateBegin,$DateEnd)
  4. $Year = floor($MonthsBetween : 12)
  5. $Month = floor($MonthsBetween mod 12)
  6. $Day = floor(daysBetween(addYears(addMonths($DateBegin,$Month),$Year),$DateEnd))
answered