Time conversion

  • Thread starter Thread starter newave
  • Start date Start date
N

newave

Guest
I am having a problem with a field that has data in it. The data is enter in number of seconds, ie. 180 seconds.

I want to be able to convert that time into hours:minutes:seconds. Any ideas on how I go about doing this.

Any suggestions would be greatly appreciated.

Jonathan
 
Use \ and Mod

Code:
Public Function TimeFromSeconds(ByVal Seconds As Long) As String
  Dim hh As Long
  Dim mm As Integer
  Dim ss As Integer
  
  hh = Seconds \ 3600
  
  Seconds = Seconds Mod 3600
  
  mm = Seconds \ 60
  ss = Seconds Mod 60
  
  TimeFromSeconds = _
    Format$(hh, "00") & ":" & _
    Format$(mm, "00") & ":" & _
    Format$(ss, "00")
  
End Function

Bear in mind if you exceed 24 hours you might get something like 30:12:59
 
If you don't want to create a function, try this in a query grid column (replacing Seconds with the field name):

Field: hhmmss: Format([Seconds]\(60*60),"00") & ":" & Format([Seconds]\60 Mod 60,"00") & ":" & Format([Seconds] Mod 60,"00")
Show: check
 

Users who are viewing this thread

Back
Top Bottom