Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MS Access Convert Seconds into hh:mm:ss

Status
Not open for further replies.

mischief911

Technical User
Jan 14, 2002
21
US
Does anyone know a simple way to convert seconds to hh:mm:ss format. Access doesn't have a native Mod() function so I am finding this seemingly simple task to be very challenging.

Any ideas would be appreciated.

Thank you.
 
Access does have a built-in MOD function. Here's an example from Help on MOD:

This example uses the Mod operator to divide two numbers and return only the remainder. If either number is a floating-point number, it is first rounded to an integer.

Dim MyResult
MyResult = 10 Mod 5 ' Returns 0.
MyResult = 10 Mod 3 ' Returns 1.
MyResult = 12 Mod 4.3 ' Returns 0.
MyResult = 12.6 Mod 5 ' Returns 3.
 
Code:
Public Function basSec2HrMinSec(SecIn As Long) As String

    'Michael Red    6/14/02
    'Convert Seconsd (as a LONG or Integer) to String like "hh:mm:ss"
    'Sample Usage:  ? basSec2HrMinSec(450)
    '7:30
    '? basSec2HrMinSec(450 + 3600 + 86400)
    ' 25:7:30

    '? basSec2HrMinSec(450 + 3600)
    '1:7:30

    '? basSec2HrMinSec(450 + 10000)
    '2:54:10


    Dim MyTime As Double
    Dim MyHrs As Long
    Const SecsPerDay = 86400

    'Convert raw seconde to a regular date / time
    MyTime = SecIn / SecsPerDay
    MyHrs = Int(MyTime * 24)
    

    basSec2HrMinSec = str(MyHrs) & ":" & Format(MyTime, "n:ss")

End Function
]/code]

Od COURSE, as usual the above is intended strrictly for illustration purposes, and NOT for prodution application use.  It would require error trapping as well as some rigorous testing prior to any real world application.

 MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top