I am having two time span such as “13:00:04” and “15:45:45”
I want to get the difference in hours minutes and seconds
Try this approach with Assign activity
time1 = "13:00:04"
time2 = "15:45:45"
span1 = TimeSpan.Parse(time1)
span2 = TimeSpan.Parse(time2)
difference = span2 - span1
hours = difference.Hours
minutes = difference.Minutes
seconds = difference.Seconds
Sample Code:
TimespanDemo.xaml (7.4 KB)
Output:

Thanks,
Ashok ![]()
You can use the below expression in assign activity,
- Assign -> timeSpan1 = TimeSpan.Parse("13:00:04")
- Assign -> timeSpan2 = TimeSpan.Parse("15:45:45")
- Assign -> differenceString = (timeSpan2 - timeSpan1).ToString("hh:mm:ss")
Hope it helps!!
In Addition to above we should keep in mind:

so we have to escape the : by \
for:

And can always recommend to do RnD within the immediate panel
Understanding the 6 Debugging Panels of UiPath in the easiest way possible! - News / Tutorials - UiPath Community Forum
Hi @Ritaman_Baral ,
Sample UiPath Workflow:
- Assign Activity:
startTime = "13:00:04"endTime = "15:45:45"
- Assign Activity:
startTimeSpan = TimeSpan.Parse(startTime)endTimeSpan = TimeSpan.Parse(endTime)
- Assign Activity:
difference = endTimeSpan - startTimeSpan
- Assign Activity:
hours = difference.Hoursminutes = difference.Minutesseconds = difference.Seconds
- Write Line Activities:
Write Line: hours.ToString()Write Line: minutes.ToString()Write Line: seconds.ToString()
Regards
Sandy
Here in one line
CStr(cdate(dat_ddMMyyyy).Hour-CDate(dat_dd_MM_yy).Hour) +":"+ Cstr(cdate(dat_ddMMyyyy).Minute-CDate(dat_dd_MM_yy).Minute) +":"+ CStr(cdate(dat_ddMMyyyy).Second-CDate(dat_dd_MM_yy).Second)
Where variables dat_ddMMyyyy = “15:45:45” and dat_dd_MM_yy = “13:00:04”
output As String.
Let me if any changes
Regards
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.
