james365
(James winston)
November 8, 2025, 9:43pm
1
I am trying to calculate age from a given date of birth in UiPath. I want to know the most efficient way to do this, either using built-in activities or expressions. Any examples or workflows would be helpful.” If you want, I can also draft the full post ready to copy-paste for the forum with proper formatting and code snippet placeholders. Do you want me to do that?
pikorpa
(Piotr Kołakowski)
November 8, 2025, 10:25pm
2
Hey @james365
you can use this expression:
(DateTime.Today.Year - dateOfBirth.Year) -
If(DateTime.Today < dateOfBirth.AddYears(DateTime.Today.Year - dateOfBirth.Year), 1, 0)
Hi @james365
There are various ways to do this. Also depends if it’s just one value or you are reading data from excel or some other input source.
main steps would be to read the birthdate of person, calculate the difference between now and the birthdate and the convert that into years.
I am attaching few posts here that have different ways to do the same, please refer
@nameless thanks for the hint
Yes is a quick approach and not accurate when now is before persons birthday.
It was choosen for introduction into coding
.Days/365 is ignoring Leap years ( no tragic catastrophe)
BirthDay in Future
[grafik]
Birthday in the past
[grafik]
[grafik]
[grafik]
Find starter help:
CheckAge.xaml (9.0 KB)
I was looking here for a solution, but in trying some things on my own I found an easier and more precise solution for whole number ages from birthdate:
cint(math.Truncate(DateDiff(DateInterval.Day, convert.ToDateTime(dob),now)/365.2422))
Ex: dob = “10/26/78” would yield 40 but dob = “10/27/78” would yield 39 if today is 10/26/18
@Muneer_Alrashdan
To convert date on excel…use format cell activity and try changing the format as required…
For the age you can directly caculate using excel formula…for that you need to write the below formula in the first cell which is L2 using a write cell activity and then use auto fill formula activity
"=TRUNC(YEARFRAC(K2,TODAY()))"
Hope this helps
Cheers
Hope this helps.