Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Posts
    905
    Thanks
    23
    Thanked 5 Times in 5 Posts

    finding the sum of times

    Hi there,

    I'm after some thoughts on how to go about adding up times. The times are all in the format of HH:MM:SS

    so ...

    10:20:02

    that would be 10 hours, 20 minutes and 2 seconds.. now say I have

    10:20:02
    02:10:42
    13:21:11

    I need to add all those up...

    Does anyone have any help or pointers to functions that can help with this?

    Many thanks

  • #2
    Regular Coder bacterozoid's Avatar
    Join Date
    Jun 2002
    Location
    USA
    Posts
    490
    Thanks
    24
    Thanked 35 Times in 35 Posts
    Add up the hours, minutes, and seconds individually. If the times are stored as strings, use the explode function to split each time up.

    10:20:02
    02:10:42
    13:21:11
    ---------
    25:41:55

    After you've done that, you'll have to look at the seconds. If it's more than 59, you'll need to increment your minutes by 1. If it's more than 119, you'll haev to increment your minutes by 2, etc. Just divide by 60 and round.

    The same is true for your minutes...if you have too many minutes, you'll need to increment your hours value.

    That should get you going in the right direction. The code shouldn't be that complex in the end.

  • Users who have thanked bacterozoid for this post:

    sir pannels (03-18-2010)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •