|
-
Aug 14th, 2007, 08:35 AM
#1
Thread Starter
Hyperactive Member
[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 ?
-
Aug 14th, 2007, 11:23 AM
#2
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")
-
Aug 16th, 2007, 03:09 AM
#3
Thread Starter
Hyperactive Member
Re: [2005] Probably Simple DateDiff question
Thanks Stanav,
That's excellent - it works a treat.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|