hh:mm:ss + hh:mm:ss values in query don't add up

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • neelsfer
    Contributor
    • Oct 2010
    • 547

    #1

    hh:mm:ss + hh:mm:ss values in query don't add up

    I first deducted the laptime and actualstarttime of a race in a query using this formula and it gives me a correct lap1time value

    Lap1Time:nz(For mat([Lap1]-[Actualstarttime],"hh:nn:ss") ) = 00:51:54
    if i repeat this for lap2 to determine the lap2time value
    Lap2Time: Nz(Format([Lap2]-[lap1],"hh:nn:ss") ) = 00:00:03
    and the 3rd lap = 00:00:03

    It produces the correct time

    My problem is adding up these to laptimes to get a totaltime from the start. I dont want to just deduct the finaltime after the 3rd lap from the actualstartingt ime, as the number of laps may vary from race to race and i therefore prefer to add up the laps. My vb programming skills are lacking here.
    i think the data type is string and it is formatted as hh:mm:ss - that is the problem.

    TotalTime: Format([Lap1time]+[lap2time]+[lap3time],"hh:nn:ss")

    lap1time = 00:51:54 ; lap2time= 00:00:03 ;
    lap3time=00:00: 03

    then i get = 00:51:5400:00:0 300:00:03 which is a combination of lap1time+lap2ti me+lap3time rather than adding it up and giving you = 00:52:00
    i think the data type is string and it is formatted as hh:mm:ss - that is the problem.

    anybody out there that can relieve me of this unnecessary stress in my life by providing a solution? hehehe
    [imgnothumb]http://bytes.com/attachments/attachment/4249d1290803381/total1.jpg[/imgnothumb][imgnothumb]http://bytes.com/attachments/attachment/4250d1290803381/addlap2.jpg[/imgnothumb]
    Attached Files
    Last edited by NeoPa; Nov 27 '10, 11:04 PM. Reason: Showed pics
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    The following Logic should work, as long as you do not go past 24hrs. Total, but I'll leave that for you to test:
    Code:
    Debug.Print Format$(CDate("00:51:54")+CDate("00:00:03")+CDate("00:00:03"),"hh:nn:ss")
    Result:
    Code:
    00:52:00

    Comment

    • neelsfer
      Contributor
      • Oct 2010
      • 547

      #3
      thx mr Adezii; you saved me again!!

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        You are quite welcome, but after all I am a little more familiar with the DB than most (LOL).

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32669

          #5
          The general rule of keeping dates and times in DateTime format for storage and string format only for displaying values is a good one that would save you from this problem.

          Comment

          Working...