[RESOLVED] [2005] Probably Simple DateDiff question
Hello,
I have two DateTimePickers on my form (They are formatted to only show the time) and would like to get the number of hours difference between the two times.
I'm using the code below which appears to work fine if it is whole hours, but not if it is only for say half an hour :
Code:
Dim Hours As Double
Hours = DateDiff(DateInterval.Hour, dtpFrom.Value, dtpTo.Value)
txtHours.Text = Hours
What am I doing wrong please ?
Re: [2005] Probably Simple DateDiff question
The DateDiff function return a Long (which is an Int64), so it essentially a whole number.
Try this
Code:
Dim ts As TimeSpan = dtpTo.Value - dtpFrom.Value
txtHours.Text = ts.TotalHours.ToString("0.00")
Re: [2005] Probably Simple DateDiff question
Thanks Stanav,
That's excellent - it works a treat. :thumb: