Example of Using a Date and Time Variable

In the documentation for Date and Time Variables the example states: To exemplify how you can work with a date and time variable, we are going to build an automation that gets the current date and time, subtracts a specific amount of time and writes the result to a Microsoft Excel spreadsheet.

ok so part of the steps are the following"
7.Add another Assign activity under the previous one.

8.In the Properties panel, in the To field, add the timLastTime variable.

9.In the Value field, type timToday.Subtract(timSpan). This is going to subtract the default value of the timSpan variable from the current date and time, stored in the timToday variable

When I do step 9 I get a message saying "Substract is not a member of UIPath .Core.GenericValue,
Could someone help?
Thanks in advance!

Hi @IngridJB
I think it’s because your timToday variable type is not DateTime.
Here is an example:
ex1.xaml (8.5 KB)

1 Like

Oh my goodness @ovi you are right…duh…I tried to change it straight from the Designer panel but I don’t see a DateTime option?

You have to Browse for types in the Variable type and search for “DateTime”


Awesome thank you !! Sorry for the delay in respons.

How can we Subtract Current day with Previous day .

Ex: to get exact age of a person.

Hi @balu,

(EndDate - StartDate).TotalDays


you mean (current date - dob).totaldays


hi @balu,

yes you are right.

(Currentdate- DOB).TotalDays will return the difference between those dates.


can you provide a sample xaml for these ?


Hi arivu96,

It works fine but TotalDays is showing the days but i need result in terms of age.
How to get it ?

Ex: (current date - DOB) = Age (in years and months (28y 8m))

Hi @balu,

Refer this
Age Calculation

DateTime birthday=new DateTime(1991,08,27)
String Age=Math.Round(Convert.ToDouble((((DateTime.Now.Year - birthday.Year) * 372 + (DateTime.Now.Month - birthday.Month) * 31 + (DateTime.Now.Day - birthday.Day)) / 372)),2).ToString

Age : 26.5



Got it bro thanks :slight_smile:
IS these result accurate?


Cdate(currentdate) - Cdate(Dob)…try this…it will help you…

can you give brief on that or a sample xaml would be helpfull

can you please send your age calculate bot on hari.gaikwad@soprasteria.com

Great. TQ. Even I was wondering with this.