I have a date and I want to calculate #Days to next birthday.
DOB=10/23/2001
What would be the formula expression I would use?
Thank you
Solved! Go to Solution.
Hi @pvara
You will need to use the datetimediff function in a formula.
Here's some documentation to give you your solution
https://help.alteryx.com/9.5/Reference/DateTimeFunctions.htm
Cheers,
B
I tried
datetimediff(datetimenow(),[DOB],"Days")
But I am not getting the expected result.
Given the date, I am expecting 364 days for next birthday
How did you know my birthday?
IF
DateTimeDiff(Left(DateTimeStart(),4)+"-"+Right(DateTimeParse([DOB],"%m/%d/%Y") ,5),DateTimeStart(),"Days") > 0
THEN
DateTimeDiff(Left(DateTimeStart(),4)+"-"+Right(DateTimeParse([DOB],"%m/%d/%Y") ,5),DateTimeStart(),"Days")
else
DateTimeDiff(Left(DateTimeAdd(DateTimeStart(),1,"Year"),4)+"-"+Right(DateTimeParse([DOB],"%m/%d/%Y") ,5),DateTimeStart(),"Days")
ENDIF
If the difference of today and my birth month & day (using this calendar year) is not a negative number of days, then those days are the answer. Otherwise count the days until my birth month & day (using next calendar year). Note: I edited the formula to use DateTimeAdd(). Without the add of 1 year this way, the formula would fail on leap days.
Cheers,
Mark
P.S. Since you asked for a formula, I nested all of the date calculations so that they would fit into a single formula.