Expand my Community achievements bar.

SOLVED

Adding hours & minutes

Avatar

Level 1

I am creating a form for staff to enter in the actual hours and minutes that they spend with a client each ses

sion and I cannot figure out how to get the time to add up correctly.  I am looking for minutes not fractions of minutes.

Example: Sarah sat with Joey for 1 hour and 25 minutes and sat with Jill for 30 minutes - must add up as 1:55

I have searched the web many times and can find nothing. Does anyone have any suggestions?

1 Accepted Solution

Avatar

Correct answer by
Former Community Member

Write code that changes everythig to a common unit (i.e. minutes). Then you can add them up and get a total number of minutes. Then finally you can divide by 60 to get the hours and the reminder will be the number of minutes you have. So if you end up with 183 minutes you woudl have 3 hrs and 3 mins.

Make sense?

Paul

View solution in original post

5 Replies

Avatar

Correct answer by
Former Community Member

Write code that changes everythig to a common unit (i.e. minutes). Then you can add them up and get a total number of minutes. Then finally you can divide by 60 to get the hours and the reminder will be the number of minutes you have. So if you end up with 183 minutes you woudl have 3 hrs and 3 mins.

Make sense?

Paul

Avatar

Level 1

Yes, it does thank you.  Can I make a subform that will do the calculations behind the scenes so it is not on the form? If so, how? I know how to create a subform but all the intricate workings of one is a mystery to me at this time.

Avatar

Former Community Member

Paul,

I ran across this OLD thread while researching a problem and hoped you could expand just a bit.

I am trying to add hours and minutes, just as above. However, I report everything in fifteen minute increments.

Example:     1.15 = one hour fifteen minutes

                    1.30 = one hour thirty minutes

When I add as you suggested, I get 165 minutes / 60 = 2.75 hours. I need this answer to display as 2.45 (two hours and 45 minutes). If I add these with normal math, the above problem works correctly, but the answer doesn't compute correctly with other time variables:

Example:      1.30 + 1.30 = 2.60 instead of 2 hours.

any ideas on how I can add these in 15 minute increments?

thanks!

Gene-O

Avatar

Level 1

Hello Gene-O

Don't take this the wrong way.... buuuut your problem is in your math.  1.15 is not equal to 1 hour and 15 minutes.  1.25 is equal to 1 hour 15 minutes. 165/60 does equal 2.75 hours. 

You are trying to get this type of time:  1:15 (1 hour 15 minutes - notice the colon)

You actually have to do a conversion and then re-convert it back to

I have a form with columns of time in this format HH:MM (hours are seperate column & minutes are a seperate column.)

 

var dMin = Page1TotalMinutes      (Page1TotalMinutes is a seperate formula in a different cell in the table)

var dHrs = Round (dMin / 60, 2)

dMin = Round( Mod(dHrs, 1) * 60)

$.formattedValue = Concat(dHrs, ":", dMin)

if (dMin <=9) then    

     $.formattedValue  = Concat(dHrs, ":0", dMin) 

      elseif (dMin >=10) then

      $.formattedValue = Concat(dHrs, ":", dMin)

endif

     

  

If you didn't want to use multiple cells for your formula, I could've made my Page1TotalMinutes another variable in the above code like this

var Page1TotalMinutes = sum (HoursTotal1 + MinutesTotalPage1) (But again I have HoursTotal1 & MinutesTotalPage1 in different cells that could be made into yet another variable like I did above)

Message was edited by: JillOfAllTrades72 @3:15 on 9/11/13

The following has evaluated to null or missing: ==> liqladmin("SELECT id, value FROM metrics WHERE id = 'net_accepted_solutions' and user.id = '${acceptedAnswer.author.id}'").data.items [in template "analytics-container" at line 83, column 41] ---- Tip: It's the step after the last dot that caused this error, not those before it. ---- Tip: If the failing expression is known to be legally refer to something that's sometimes null or missing, either specify a default value like myOptionalVar!myDefault, or use <#if myOptionalVar??>when-present<#else>when-missing. (These only cover the last step of the expression; to cover the whole expression, use parenthesis: (myOptionalVar.foo)!myDefault, (myOptionalVar.foo)?? ---- ---- FTL stack trace ("~" means nesting-related): - Failed at: #assign answerAuthorNetSolutions = li... [in template "analytics-container" at line 83, column 5] ----