Time calculations

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jamesd0142
    Contributor
    • Sep 2007
    • 471

    Time calculations

    Ok i have bashed my head against a wall trying to work out how this is done... please help.

    i have 2 text boxes with the values:

    txt1.text = "15:27:06"
    txt2.text = "1:05:27"

    Now if txt2.text = the current time and i want the time when it was txt1.text (15hours,27mins ,6seconds) ago how do i do it...

    for example current time is "01:05:27" and if i subtract "15:27:06" away i should get time as "09:38:31"

    any1 able to help?
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    Look at the MSDN for the DateTime object.

    You can subtract one DateTime from another DateTime, then take the .ToString() of the result.

    Comment

    • jamesd0142
      Contributor
      • Sep 2007
      • 471

      #3
      Static LOF As DateTime = "15:27:06"
      Static RT As DateTime = "1:05:27"

      MsgBox(RT.Subtr act(LOF).ToStri ng)

      answer = "-14:19:38"
      RUBBISH :(

      ----------------------
      if its "1:05:27" and u go back "15:27:06" i should get "09:38:31"

      so im really confused?

      Comment

      • tlhintoq
        Recognized Expert Specialist
        • Mar 2008
        • 3532

        #4
        If you don't specify the date, then both times are on the same date. Therefore the math woks.

        There is no assumption made that 0100 is on Tuesday and 1500 is on Monday.
        Computers don't assume.

        You didn't go read up on the DateTIme object in the MSDN did you? You just started using it with a "let's see if this works" mindset. Kinda like when a 4 year old sticks a fork in an outlet: I wonder what this will do?

        Comment

        • jamesd0142
          Contributor
          • Sep 2007
          • 471

          #5
          Originally posted by tlhintoq
          If you don't specify the date, then both times are on the same date. Therefore the math woks.

          There is no assumption made that 0100 is on Tuesday and 1500 is on Monday.
          Computers don't assume.

          You didn't go read up on the DateTIme object in the MSDN did you? You just started using it with a "let's see if this works" mindset. Kinda like when a 4 year old sticks a fork in an outlet: I wonder what this will do?
          No your right... i did just jump in without reading.
          ill do a little more reading :) thanks for the help

          Comment

          • Frinavale
            Recognized Expert Expert
            • Oct 2006
            • 9749

            #6
            You can use one of the DateTime.TryPar se() methods to parse a string into a DateTime Structure which can be used to work with Times. Check out the DateTime structure link that I posted for examples on how to work with DateTime objects.

            Comment

            • shekoasinger
              New Member
              • May 2010
              • 4

              #7
              James already gave the right asnwer but he was a little confused:

              Static LOF As DateTime = "15:27:06"
              Static RT As DateTime = "1:05:27"
              MsgBox(LOF.Subt ract(RT).ToStri ng)

              you can also replase the times with:
              Static LOF As DateTime = textbox1.text
              Static RT As DateTime = textbox2.text
              MsgBox(LOF.Subt ract(RT).ToStri ng)

              Comment

              Working...