Error calculating difference between dates?


I am having an issue when calculating the time between two different dates. Please see the file (10.2 KB)

This issue happens when setting one of the times to be later than noon. ie: 13:00:00



You should use “HH:mm:ss” instead of “hh:mm:ss” because “hh” means the hour, using a 12-hour clock.



This looks perfect and gives out the output we need in total hours
may i know what is the requirement
Cheers @rileythiessen

Just to note on @yoichi’s point, the formatting should not matter when taking a difference between dates because you should be taking the difference of two DateTimes rather than strings. The formatting just affects the string output.

@rileythiessen so you need to convert the two dates to DateTimes. Then, you just do date1-date2 which will return a timespan if I remember correctly. Do some searches on how to do that. I think you will need to use DateTime.Parse() or ParseExact. Also, Convert.ToDateTime() or CDate() work well if your datesstrings are in MM/dd formats rather than dd/MM. Make sure to also check that the string is a date before conversion as well with DateTime.TryParse() or IsDate()


Thank you very much for the speedy reply! That was it :slight_smile:

1 Like

Thank for the reply, the issue I was having was resolved by Yoichi :slight_smile:

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