Difference of Intime and Outtime

Can anyone please suggest the way to get the difference of time from excel in the total hours field

Date Day Intime Outtime Total Hours

01-Aug-2020 Mon 10.00AM 7.00PM
02-Aug-2020 Tue 10.30AM 7.30PM

Hi @vidhan.rpa

What is your In Time & Out Time ??

Happy Automation :raised_hands:

Best Regards
Er Pratik Wavhal :robot::man_technologist:t4: :computer:

Intime and outtime is mentioned above, time with AM is intime and PM is out time, plz check

Are these all separate fields in excel? And do you want the solution as an excel formula or uipath solution?

It seems like the easiest would just be relatively simple excel formula, but it can be done using uipath fairly simply as well by creating a datetime variable for Intime, a datetime variable for Outtime, then figuring out the TimeSpan between the 2 datetime variables

Yes these are separate excel fields, plz provide the uipath solution.

Use Datetime.ParseExact to construct the 2 datetime variables for each row (InTime and OutTime). You will want to use this string/datetime formatting guide for help with this: Custom date and time format strings | Microsoft Learn

Now that you have 2 datetime variables, you can use the DateTime.Subtract method to give you a TimeSpan variable DateTime.Subtract Method (System) | Microsoft Learn

This TimeSpan can then be formatted however you’d like when converting it back to string to paste into the “Total Hours” field of your datatable: TimeSpan.ToString Method (System) | Microsoft Learn

Please let me know if you are having trouble with any part of this. Let me know what you have tried and which part is not working. I would highly recommend attempting to figure it out on your own instead of having someone create it for you, as that is the only way you’ll be able to learn & apply that learning to future projects

Hi @vidhan.rpa

Input along with Output :-

Do below Steps :-

String inTime = “01 Aug 2020 10:00 AM”

String outTime = “01 Aug 2020 07:30 PM”

TimeSpan diff = DateTime.ParseExact(CDate(outTime).ToString("dd MMMM yyyy hh:mm tt"), "dd MMMM yyyy hh:mm tt", System.Globalization.CultureInfo.InvariantCulture).Subtract(DateTime.ParseExact(CDate(inTime).ToString("dd MMMM yyyy hh:mm tt"), "dd MMMM yyyy hh:mm tt", System.Globalization.CultureInfo.InvariantCulture))

Also you can refer below thread :-

Mark as solution and like it if this helps you :slight_smile:

Happy Automation :raised_hands:

Best Regards
Er Pratik Wavhal :robot::man_technologist:t4: :computer: