Announcement

Collapse
No announcement yet.

Sum a Range of Hours, Minutes, Seconds

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Sum a Range of Hours, Minutes, Seconds

    Assume:

    1:03:00
    -1:03:00
    -0:00:00
    8:24:00
    9:25:00
    -2:54:00

    I want to have an Array and return the Total for Hours/Minutes/Second.

    Any suggestions?



    ------------------
    -Greg
    -Greg
    [email protected]
    MCP,MCSA,MCSE,MCSD

  • #2
    The only suggestion I have is to do it the old-fashioned way:

    Extract all the hoursfrom the hh:mm:ss, multiply by 24 * 60
    Extract all the minutes, multiply by 60
    Extract and add the seconds.

    You now have a total number of seconds.

    Divide as needed for desired target time units.

    Seems faster than digging thru MSDN and the API reference.

    MCM
    Michael Mattias
    Tal Systems (retired)
    Port Washington WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      Convert to seconds and store 'em that way. You'll only have a single value to deal
      with and you can readily do calculations. Convert 'em back to displayable values
      when you need to display 'em.

      ------------------
      Tom Hanlin
      PowerBASIC Staff

      Comment


      • #4
        What storage structure are you using for the hh:mm:ss?

        It seems to me that you should be able to do the math directly on the
        seconds, minutes and hours (separately) without the need to convert all
        to seconds. Just be sure to carry any overflow of seconds or minutes
        forward. Of course, this assumes that you are storing the hours,
        minutes and seconds in unique vars (array elements).



        ------------------
        Bernard Ertl
        Bernard Ertl
        InterPlan Systems

        Comment


        • #5
          Bern and Tom,

          I think the easiest way to do it would be the way Tom discribes.

          I'll post some working code when I'm finished with it.

          ------------------
          -Greg
          -Greg
          [email protected]
          MCP,MCSA,MCSE,MCSD

          Comment

          Working...
          X
          😀
          🥰
          🤢
          😎
          😡
          👍
          👎