Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. How to calculate the time difference

How to calculate the time difference

Scheduled Pinned Locked Moved Visual Basic
tutorialquestion
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    re infecta
    wrote on last edited by
    #1

    How to calculate time difference in hours between two dates, let's say 01/01/01 12:00 and 02/02/07 7:00?

    M G W 3 Replies Last reply
    0
    • R re infecta

      How to calculate time difference in hours between two dates, let's say 01/01/01 12:00 and 02/02/07 7:00?

      M Offline
      M Offline
      MatrixCoder
      wrote on last edited by
      #2

      Just use the DateTime.Subtract function, like so:

      Dim FirstDate As New DateTime(2007, 2, 2, 7, 0, 0)
      Dim SecondDate As New DateTime(2001, 1, 1, 12, 0, 0)
      Dim FinalDate As TimeSpan = FirstDate.Subtract(BDayNow)

      Hope this helps!


      Trinity: Neo... nobody has ever done this before. Neo: That's why it's going to work.

      1 Reply Last reply
      0
      • R re infecta

        How to calculate time difference in hours between two dates, let's say 01/01/01 12:00 and 02/02/07 7:00?

        G Offline
        G Offline
        Guffa
        wrote on last edited by
        #3

        You can subtract DateTime values, the result is a TimeSpan. You can use the TotalHours property to get the time difference. Example: Dim startTime as DateTime = new DateTime(1, 1, 1, 12, 0, 0) Dim endTime as DateTime = new DateTime(7, 2, 2, 7, 0, 0) Dim diff as TimeSpan = endTime - startTime Dim hours as Double = diff.TotalHours;

        --- single minded; short sighted; long gone;

        1 Reply Last reply
        0
        • R re infecta

          How to calculate time difference in hours between two dates, let's say 01/01/01 12:00 and 02/02/07 7:00?

          W Offline
          W Offline
          Werries
          wrote on last edited by
          #4

          Hi there, You can use the 'DateDiff' function, realy easy to work with. Regards, Werries

          A programmer's life is good... or is it?? Ek dink nie so nie!

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups