Results 1 to 3 of 3

Thread: [RESOLVED] [2005] Probably Simple DateDiff question

  1. #1

    Thread Starter
    Hyperactive Member Jonny1409's Avatar
    Join Date
    Mar 2005
    Posts
    308

    Resolved [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 ?

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    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")

  3. #3

    Thread Starter
    Hyperactive Member Jonny1409's Avatar
    Join Date
    Mar 2005
    Posts
    308

    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
  •  



Click Here to Expand Forum to Full Width