How to get the difference between two dates
Question

Is there any convenient ways to find out the difference between two dates? 

Solution

hey, you can use this built-in logic function for this problem.

see this documentation for more: https://success.outsystems.com/Documentation/11/Reference/OutSystems_Language/Logic/Built-in_Functions/Date_and_Time#DiffDays

You may try the build-in function 

such as

DiffDays(dt1, dt2)

example: 

DiffDays(#1982-05-19#, #1982-05-21#)

output\: 2

In the build in functions



We cannot use "-" in date format but if we need to find the difference between two dates we may use following equation.


Concat("  Year = ",Concat(IntegerToText(Trunc(DiffDays(Person.DateOfBirth,CurrDate())/365)),


Concat(" , Month = ",Concat(IntegerToText(Trunc((365-((DiffDays(Person.DateOfBirth,CurrDate())/365- Trunc(DiffDays(Person.DateOfBirth,CurrDate())/365))*365))/12)),

Concat(" , Days = ",IntegerToText(Trunc((((365-((DiffDays(Person.DateOfBirth,CurrDate())/365- Trunc(DiffDays(Person.DateOfBirth,CurrDate())/365))*365))/12
)-Trunc((365-((DiffDays(Person.DateOfBirth,CurrDate())/365- Trunc(DiffDays(Person.DateOfBirth,CurrDate())/365))*365))/12
))*12))
)) )   ))



Difference between Current date & DOB.png

MY ISSUE WAS I WANT TO KNOW THE EXACT AGE , IF I AM HAVING BATE_OF_BIRTH


Yesterday I was searching for a solution for this issue but i did not find the answers suitable for my issue, hence i have tried it my own and yesterday itself posted that solution here but later on i find my solution need to be more precise and should be small so i have created new one for me kindly check if it solves your problem too,


 If(Year(Person.DateOfDeath)<>1900,"He/she already passed away on "+Person.DateOfDeath,

Concat("Year = ",Concat(Year(CurrDate())-Year(Person.DateOfBirth),Concat(", Month = ",Concat(If((Month(CurrDate())-Month(Person.DateOfBirth))<0,12+(Month(CurrDate())-Month(Person.DateOfBirth)),Month(CurrDate())-Month(Person.DateOfBirth)),Concat(", Day = ",If((Day(CurrDate())-Day(Person.DateOfBirth))>0,(Day(CurrDate())-Day(Person.DateOfBirth)),(Day(Person.DateOfBirth))-(Day(CurrDate())))))))))
Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.