• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Adding times together

Contributor ,
May 14, 2014 May 14, 2014

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.

Views

351

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 14, 2014 May 14, 2014

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>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 18, 2014 May 18, 2014

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 18, 2014 May 18, 2014

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
May 18, 2014 May 18, 2014

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation