Caculate time difference between two DateTime variables

Hi All!

I have startTime and an endTime as DateTime variable that looks like 2019-12-02 08:00:00 and 2019-12-02 11:45:00. I want to calculate the hours and minutes so it results in a String and look like: 3.75.

Thank you!

2 Likes

Hi @JackALope

use below code

(DateTime.ParseExact("12/30/1899 18:00:00", "MM/dd/yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture)-DateTime.ParseExact("12/30/1899 08:30:00", "MM/dd/yyyy HH:mm:ss", System.Globalization.CultureInfo.InvariantCulture)).TotalHours.ToString()

Regards,
Kommi Jeevan.

5 Likes

span.xaml (5.8 KB)

Thanks!

1 Like

@JackALope,

Welcome to UiPath Community!.

Try like the following,

Convert.ToString( (DateTime.ParseExact("2019-12-02 08:00:0", "yyyy-MM-dd hh:mm:ss",System.Globalization.CultureInfo.InvariantCulture)-DateTime.ParseExact("2019-12-02 11:45:00", "yyyy-MM-dd hh:mm:ss",System.Globalization.CultureInfo.InvariantCulture)).Hours)
2 Likes

Hi @JackALope

just minus it
check this screen shot

Regards,
Gulshiyaa

3 Likes

I have create workflow based on requirement please check I hope you will get the solution.

Time Diff.xaml (4.7 KB)

4 Likes

Thank you a lot! The thing is that I would like the minutes to be devided into hours, so if you have a time difference of 3 hours and 45 minutes, this should result in 3.75 instead of 3.45. :smiley:

Try this:
grafik

2 Likes

Thank you so much everyone! :slight_smile:

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