How to calculate the time taken

I want to send an email at the end of my workflow that tells me how long the process took to complete. I have set a “Start_Time” variable at the start and a “End_Time” variable at the end. both of witch have been set using this code “Start_Time = DateTime.Now.ToString(“hh:mm:ss”)”. Obviously, replacing “Start” with “End” for the “End_Time” variable. To calculate the Time taken ive used this code “(CDate(End_Time) - CDate(Start_Time)).ToString”. This works well. however if the process is started at a time such as 12:58 and ends at 1:03 then i get this result.
image

Does anyone know a way to fix this?

Thanks

Hi,

Can you try the following?

Start_Time = DateTime.Now.ToString("HH:mm:ss")

BTW, I think perhaps you should use DateTime type directly.

dtStartTime = DateTime.Now
dtEndTime = DateTime.Now

Then

ts = dtEndTime - dtStartTime

ts is TimeSpan type

Regards,

1 Like

work on datetime base and bring also the date part into the picture (e.g. recognizing day shift at Midnight)
grafik

Thank you. That will work perfect

1 Like

Hey @cody.barber
The suggested answer is great!! To add up an alternative procedure you can use System.Diagnostics.Stopwatch so that you can get an accurate elapsed time.

It would be a clean, simple and easy method. Interested give it a look!!

Main.xaml (5.4 KB)

Cheers!!

1 Like

Thank you for the advice. But I don’t want the time of the whole process. I just want the time taken for a certain part of the process. However, ill look into it anyway for future prosses where I might need it. It looks very useful.

Yes… @cody.barber you can calculate the part of the process also.
Whichever activity’s elapsed time you want to calculate can place them in between the two invoke methods. :v:

oh. that sounds like it would work as well.

Thanks

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