Results 1 to 7 of 7
  1. #1
    rockcliff15 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Apr 2012
    Posts
    7

    Convert seconds to DD:HH:MM:SS

    Hi,

    I've got a report showing a list of durations of time in seconds and I want to be display them in DD:HH:MM:SS format.

    Any ideas?



    Thanks

  2. #2
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    What have you tried?

  3. #3
    randman1 is offline Novice
    Windows XP Access 2003
    Join Date
    Dec 2009
    Posts
    25
    There's no built-in function that I'm aware of but you could use this function in a standard module so it can be used anywhere in your app.

    Code:
    Public Function Sec2DHMS(lSec As Long) As String
        Dim iMin As Integer
        Dim iHour As Integer
        Dim iDay As Integer
        
        Const SecInMin As Long = 60
        Const SecInHour As Long = SecInMin * 60
        Const SecInDay As Long = SecInHour * 24
               
        iDay = Int(lSec / SecInDay)
        lSec = lSec - (iDay * SecInDay)
        iHour = Int(lSec / SecInHour)
        lSec = lSec - (iHour * SecInHour)
        iMin = Int(lSec / SecInMin)
        lSec = lSec - (iMin * SecInMin)
        
        Sec2DHMS = Format(iDay, "00") & ":" & Format(iHour, "00") & ":" & Format(iMin, "00") & ":" & Format(lSec, "00")
        
    End Function

  4. #4
    rockcliff15 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Apr 2012
    Posts
    7
    Quote Originally Posted by RuralGuy View Post
    What have you tried?
    I've tried [myValue]/86400 but this just gives me a decimal of number of days and I dont know how to format this as DD:HH:MM:SSS

    If it makes it any easier I could live with it being in HH:MM:SS as long as HH could go above 24 and not reset to 00.

    Thanks

  5. #5
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Did you try the suggestion randman1 posted yesterday morning?

  6. #6
    rockcliff15 is offline Novice
    Windows 7 32bit Access 2007
    Join Date
    Apr 2012
    Posts
    7

    Wink

    Quote Originally Posted by randman1 View Post
    There's no built-in function that I'm aware of but you could use this function in a standard module so it can be used anywhere in your app.

    Code:
    Public Function Sec2DHMS(lSec As Long) As String
        Dim iMin As Integer
        Dim iHour As Integer
        Dim iDay As Integer
        
        Const SecInMin As Long = 60
        Const SecInHour As Long = SecInMin * 60
        Const SecInDay As Long = SecInHour * 24
               
        iDay = Int(lSec / SecInDay)
        lSec = lSec - (iDay * SecInDay)
        iHour = Int(lSec / SecInHour)
        lSec = lSec - (iHour * SecInHour)
        iMin = Int(lSec / SecInMin)
        lSec = lSec - (iMin * SecInMin)
        
        Sec2DHMS = Format(iDay, "00") & ":" & Format(iHour, "00") & ":" & Format(iMin, "00") & ":" & Format(lSec, "00")
        
    End Function
    Just tried this and its perfect!

    Thanks

  7. #7
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Glad to hear you got it sorted.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Can you convert .mdb to .wdb??
    By DeeMax45 in forum Access
    Replies: 2
    Last Post: 01-22-2012, 06:11 PM
  2. Convert seconds to HH:MM:SS format
    By sai_rlaf in forum Access
    Replies: 2
    Last Post: 01-19-2012, 12:57 AM
  3. Form opens for only seconds
    By MFS in forum Programming
    Replies: 5
    Last Post: 11-04-2010, 09:33 PM
  4. How to convert a db to txt
    By Joliet_Jake in forum Import/Export Data
    Replies: 5
    Last Post: 11-01-2010, 12:07 AM
  5. Automatically close form in 5 seconds
    By alaric01 in forum Forms
    Replies: 4
    Last Post: 09-21-2010, 04:25 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums