Results 1 to 2 of 2

Thread: DateDiff Question

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2008
    Location
    Philippines
    Posts
    218

    DateDiff Question

    Hi guys,

    Code:
    ? dateDiff("n","08:30","09:40")/60
    1.1666666666666667 --result
    How should I get the result as 1 hour and 10 minutes here ?

    Thank you

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: DateDiff Question

    Don't use DateDiff. Whether you're using DateTime values or TimeSpan values (which you should be using one of) then you can simply subtract one from the other to get a TimeSpan that represents the difference.
    vb.net Code:
    1. Dim start As New TimeSpan(8, 30, 0)
    2. Dim finish As New TimeSpan(9, 40, 0)
    3. Dim difference As TimeSpan = finish - start
    4.  
    5. MessageBox.Show(String.Format("{0}:{1:00}", difference.Hours, difference.Minutes), "Difference")
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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