Hello Alteryx Users,
I am looking for the solution on how to calculate the age in 16years, 5 months, 21 Days format (Years, Months, Days) from Birthdate field (the data is in this format 1971-10-25 00:00:00)
Thanks
Solved! Go to Solution.
I use three sequential formulas to return the years/months/days past since the date entered. The DateTImeDiff( function has the Floor( function built in so only integer values are returned. This information is the key to the method below.
Years:
DateTimeDiff(
DateTimeToday()
,[Birthday]
,"Years")
Months:
DateTimeDiff(
DateTimeToday()
,DateTimeAdd([Birthday],[Years]*12,"Months")
,"Months")
Days:
DateTimeDiff(
DateTimeToday()
,DateTimeAdd([Birthday],([Years]*12)+[Months],"Months")
,"days")
Check out the attached workflow to see this in action.
thanks @CharlieS
Dear @CharlieS
I hope you and family in good health ...
Would you mind explaining the meaning of the formula below, particularly for the "months" and "days"? (in particular, the blue one)
Years:
DateTimeDiff(
DateTimeToday()
,[Birthday]
,"Years")
Months:
DateTimeDiff(
DateTimeToday()
,DateTimeAdd([Birthday],[Years]*12,"Months")
,"Months")
Days:
DateTimeDiff(
DateTimeToday()
,DateTimeAdd([Birthday],([Years]*12)+[Months],"Months")
,"days")
really appreciate for your explanation ....
Hi @Ar13f
The expressions above are meant to be executed in that order. The reason is that subsequent expressions use the field above. Years are calculated first. Only after years are done, can that result be used to determine the months.
Basically we're taking the largest steps first (years), then using that result to take the next step (month), and after both of those are done we'll add the minutes. Does that make sense?