I have two variables :
Dim starttime As TimeSpan
Dim endtime As TimeSpan
My starttime value is : 02:30:00 (I mean 2.30AM)
2.30AM is next day
My endTime Value is : 10:30:00(I mean 10.30Am)
I want to get time difference of these. So I have code like this:
Dim span3 As TimeSpan = starttime .Subtract(endtime )
Now I am getting span3 : 08:00:00
This is wrong answer. Actually I want to get 16:00:00. (this is the exact differnce between 2.30Am To 10.30 Am)
How I can calculate this?
You need to use a DateTime variable to hold your start time and end time. Like this:
Dim startTime As New DateTime(2013, 9, 19, 10, 30, 0) ' 10:30 AM today
Dim endTime As New DateTime(2013, 9, 20, 2, 0, 0) ' 2:00 AM tomorrow
Dim duration As TimeSpan = endTime - startTime 'Subtract start time from end time
Console.WriteLine(duration)
Result:
15:30:00
UPDATE:
To convert that result to minutes, you can use the TotalMinutes property of the TimeSpan variable:
Console.WriteLine(duration.TotalMinutes)
Result:
930
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With