I'm getting values from two dateTimePickers and I need to get the time difference between them. Now, I'm calculating the difference using the below code, but I'm getting a wrong time difference with Milliseconds. Is there a way to calculate the time difference without considering Milliseconds. WindowsFormScreenshot
TimeSpan difference = dateTimePicker2.Value - dateTimePicker1.Value;
Example 1;
- Start time : 4/24/2022 2:30:11 PM
- end time : 4/24/2022 2:30:11 PM
- Actual difference : -00:00:00.0049863
- Expected difference : 00:00:00
Example 2;
Start time : 4/24/2022 2:29:01 PM
end time : 4/24/2022 10:29:01 PM
Actual difference : 07:59:59.9037925
Expected difference : 08:00:00
Example 3;
Start time : 4/24/2022 4:24:28 PM
end time : 4/24/2022 10:30:28 PM
Actual difference : 06:05:59.9648821
Expected difference : 06:06:00
It will give expected answers, when I'm retyping the time value in both dateTimePickers in Winform but doesn't work when I didn't retype minutes field in each dateTimePicker.
I don't want to round up the answers. I want to do the difference calculation without considering milliseconds. So that it will give correct answers for what ever the values we parse for dateTimePickers.
(I'm a newbie to c#. so I'm sorry if I'm not much clear. Thank you so much!)