Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
<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>
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
The yikes-a-roni is inevitable. To add time values, you must add hours and minutes separately, using modulo 60 arithmetic.
Copy link to clipboard
Copied
Yep I was just hoping there was some obscure function that I didn't know about.