Example of Using a Date and Time Variable

studio
variable

#1

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!
Ingrid


#2

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


#3

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?
Thanks!


#4

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


#5

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


#6

How can we Subtract Current day with Previous day .

Ex: to get exact age of a person.


#7

Hi @balu,

(EndDate - StartDate).TotalDays

Regards,
Arivu


#8

you mean (current date - dob).totaldays

Right?


#9

hi @balu,

yes you are right.

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

Regards,
Arivu


#10

can you provide a sample xaml for these ?

Thanks


#11

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))


#12

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

Output
Age : 26.5

Regards,
Arivu


Calculate Age from a given birthdate
#13

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


#14

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


#15

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


#16

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