How to Add two variables which have data type date time

Hi All,

I have 2 variables with data type DateTime. D1 & D2
i have a third variable D3 which is a DateTime variable too.
I need the output somewhat like this
D3= D1 + D2
D2= 00:00:10
output should be D3 : 12:00:32

Can someone please help me with this? I tried a bunch of options provided online but nothing is working for me.


Welcome back to the uipath community.

TimeSpan ts1 = TimeSpan.Parse(“12:00:12”)
TimeSpan ts2= TimeSpan.Parse(“00:00:10”)
TimeSpan tsSum = ts1 + ts2

Print tsSum


I need the data type to be DateTime.
as after this i have a if condition which im checking for this D3 > (other variable with Datetime.Now()) value


You can convert Timespan to Date time like below.

  DateTime DT3 = Convert.ToDateTime(ts.ToString())
1 Like

Can you please tell me how to do reverse?
ie Datetime to Timespan instead


   Timespan ts =  DateTime.TimeOfDay
1 Like

it worked for me.thanks :slight_smile:

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