364
Views
3
Comments
Solved
Difference between two dates in Years-Month-Days
Question

Hello 

I have Two dates (start date - end date i want to get the difference between this two dates in year-month-day for example 

start date: 5/01/2021 

end date : 31/05/2022

difference = 1 year-4 months-26 days 

Thanks

2021-09-06 15-09-53
Dorine Boudry
 
MVP
Solution

Hi @khaled emad ,

the thing you need to solve, is the fact that not all months have the same number of days.

See attached a demo with one way of implementing this.  Years and months can easily be calculated, for days, it uses iteration assuming a month is 28 days, and adding until real difference is found.

But this type of thing always gets weird when you want to express difference between dates at the end of the month, for example, instinctively, it feels like a full month between last day of january and last day of february, but it isn't.  So maybe ask why you even want this, what business requirement would benefit from this type of information ?


QDR_DifferenceBetweenDates.oml
2022-10-24 14-53-08
Sabrina Avolio

Provided you have to use DiffDays,


Take a look here.

 https://success.outsystems.com/Documentation/11/Reference/OutSystems_Language/Logic/Built-in_Functions/Date_and_Time?_gl=1*1sjpz0p*_ga*MjIwNDMyODk4LjE2NjEzMzQxMzc.*_ga_ZD4DTMHWR2*MTY2NjYyMDk0MS4xMTIuMS4xNjY2NjIyNjgyLjYwLjAuMA..#DiffDays

2021-09-06 15-09-53
Dorine Boudry
 
MVP
Solution

Hi @khaled emad ,

the thing you need to solve, is the fact that not all months have the same number of days.

See attached a demo with one way of implementing this.  Years and months can easily be calculated, for days, it uses iteration assuming a month is 28 days, and adding until real difference is found.

But this type of thing always gets weird when you want to express difference between dates at the end of the month, for example, instinctively, it feels like a full month between last day of january and last day of february, but it isn't.  So maybe ask why you even want this, what business requirement would benefit from this type of information ?


QDR_DifferenceBetweenDates.oml
2025-10-10 00-19-44
Bruno Rendeiro

Hy @khaled emad 

You have your solution here in JavaScript

https://stackoverflow.com/questions/17732897/difference-between-two-dates-in-years-months-days-in-javascript

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.