Problem converting seconds to hours and minutes

Liz_I3

Well-known Member
Joined
Dec 30, 2002
Messages
647
Office Version
  1. 2016
Platform
  1. Windows
Hi
I have a query that sums a the seconds for a user over a time period. I want want the sum of the total seconds to be in Hours and mininuts. I have tried on the query grid to create a new field called duration with the below formula but with 388466 seconds it returns 11:54:06 it should be 107:54:06 (The 06 seconds is optional, rounding up the minutes would be fine). What am I missing?

Duration: Format([SumOfSeconds]/86400,"hh:nn:ss")

Thanks
L
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
Hi, Liz.

That would be easy using Excel's Text function, but I don't see that Format supports the [h] formatting code. Maybe a function:

Code:
Sub demo()
  MsgBox hms(388466 / 86400#)
End Sub

Function hms(t As Date) As String
  hms = Int(t * 24) & Format(t, ":nn:ss")
End Function
 
Upvote 0
Thank you for trying to help me, but I think this issue is that my raw data is duplicating the data, therefore when I sum my seconds I am getting more seconds that can be in one day, my user can't work 107 hrs a day LOL
I have ask the IT dept to change the format of the data dump they supplied me. The formula should work correctly once I have the correct data

Thanks again for your help

L
 
Upvote 0
Can't help at all with Access, Liz. Good luck.
 
Upvote 0
Use this Function:

Code:
Public Function FormatTime(ByVal TimeInSeconds As Long) As String
  Dim h As Long, m As Long, s As Long
  h = Int(TimeInSeconds / 3600)
  m = Int((TimeInSeconds - h * 3600) / 60)
  s = TimeInSeconds - ((h * 3600) + (m * 60))
  FormatTime = h & ":" & m & ":" & s
End Function
 
Upvote 0

Forum statistics

Threads
1,215,065
Messages
6,122,944
Members
449,095
Latest member
nmaske

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top