Results 1 to 3 of 3

Thread: [2005] how to find different between to times

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2006
    Posts
    66

    [2005] how to find different between to times

    hi friends

    i need to get the diff between two dates and including the time diff also.

    there is a fun datediff from that i got date diff and

    how to the time diff?

    thanks in advance

    with regards
    ravi

  2. #2
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: [2005] how to find different between to times

    Use Timespan, you can ask it to output days, minutes, hours, seconds etc...
    Just give it the two dates, then subtract them:

    2 Code:
    1. Dim Tspan As TimeSpan
    2.  
    3. Dim date1 As Date = Date.Now
    4. Dim date2 As Date = Date.ParseExact("10/06/2007 08:23:14", "dd/MM/yyyy HH:mm:ss", System.Globalization.CultureInfo.CurrentCulture)
    5.  
    6. Tspan = date1 - date2
    7.  
    8. MessageBox.Show("Total Hours: " & Tspan.Hours.ToString & " Total Minutes: " & Tspan.Minutes.ToString)
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  3. #3
    Hyperactive Member Troy Lundin's Avatar
    Join Date
    May 2006
    Posts
    489

    Re: [2005] how to find different between to times

    There is also System.DateTime.Subtract

    I use this when tracking loading times:

    vb.net Code:
    1. Dim start As Date = Now
    2. ' Perform function
    3. MessageBox.Show(Me, Now.Subtract(start).TotalMilliSeconds)

    That will give me the difference in milliseconds.
    Prefix has no suffix, but suffix has a prefix.

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