How to calculate age?

I need to read date of birth from excel sheet and calculate the age and write the age to the excel sheet. How that can be done in UiPath? Can somone help me

Hi @sonia_thomas

You can use the DateDiff method available from the DateTime class.

  1. Get the DateDiff between date of birth and today’s date.
  2. Use the DateInterval.Year to get the difference in years.


You can use the DateDiff function.


Syntax: DateDiff(DateInterval, Date1,Date2)
Code: DateDiff(DateInterval.Day, β€œ2016-01-30”,β€œ2016-01-30”)

It will return the number of the days between the two dates as Integer Type.

Hope It helps!


Hello Sonia,
In this video I do a lot of stuff with DateTime:
In your case, you can do the difference between YEARS after you convert from String to DateTime, or you can use TimeSpan from here(TimeSpan Struct (System) | Microsoft Docs)
UiPath Tutorial for String and DateTime (Use-cases) - YouTube

20:05 DateTime to string in multiple ways
23:00 AddDays get DayofWeek
25:40 Convert from String to DateTime
26:20 Compare DateTime

Cristian Negulescu