# Calculate Age from a given birthdate

I have a string (birthdate), in this format: ddMMyyxxxxx. The x’es are just random numbers. What i want is the age of this given person. Very basic question but im having some issues finding a smooth solution for this. Been looking into using .Ticks but not gotten anywhere. I’ve been trying different formats of the string. Trying with ddMMyyyy atm

Refer this post

Regards,
Arivu

3 Likes

Thanks! Should have found that one myself but i didnt, sorry.

1 Like

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

9 Likes

This is even better, thank you!

2 Likes

That’s an excellent solution. Using it in my automation right now!

2 Likes

Hello , I am new to ui path , used the above formula to calculate age .
But issue is if someone is born in 2019 it says age as 0… Shouldn’t it be something like 0.3 or 0.4 something like that which can interpreted alike age as 3 or 4 month

Hello @sowmyakulkarni86,

I think the attached xaml file might work for you. It will calculate the age in years and months.Age Calculator.xaml (9.0 KB)

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.