4 Replies Latest reply on May 18, 2014 12:13 PM by BreakawayPaul

    Adding times together

    BreakawayPaul Level 2

      I have table with a column that holds elapsed times in an hh:mm format.  I'd like to add these times together to get a total, but I can't add something with a :, and dateadd() isn't a fan either.

       

      Any suggestions?

       

      I thought about breaking apart the hh:mm and converting the hours into straight minutes, then adding them together, but that seems clunky.

        • 1. Re: Adding times together
          BKBK Adobe Community Professional & MVP

          <cfset time1="01:23">

          <cfset timeInMins1 =60*listgetat(time1,1,":")+listgetat(time1,2,":")>

           

          <cfset time2="23:45">

          <cfset timeInMins2 =60*listgetat(time2,1,":")+listgetat(time2,2,":")>

           

          <!--- Add times --->

          <cfset totalMins = timeInMins1+timeInMins2>

           

          <!--- Pad single digits with 0 --->

          <cfset hrsPart = right('0' & int(totalMins/60), 2)>

          <cfset minsPart = right('0' & totalMins mod 60, 2)>

          hrsPart: <cfoutput>#hrsPart#</cfoutput><br>

          minsPart: <cfoutput>#minsPart#</cfoutput>

          • 2. Re: Adding times together
            BreakawayPaul Level 2

            Sorry for abandoning the thread.  We have a severe illness in the family that's taken up a lot of our time.

             

            As for adding the times, that's a bit of yikes-a-roni

             

            I just found some entries that have hours and some only minutes, so I'd have to contend with that.  Maybe I can could the list items from right to left and stop when I get a null.

            • 3. Re: Adding times together
              BKBK Adobe Community Professional & MVP

              The yikes-a-roni is inevitable. To add time values, you must add hours and minutes separately, using modulo 60 arithmetic.

              • 4. Re: Adding times together
                BreakawayPaul Level 2

                Yep I was just hoping there was some obscure function that I didn't know about.