Conversion of seconds to hours and minutes

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MMcCarthy
    Recognized Expert MVP
    • Aug 2006
    • 14387

    #16
    Make control source of your field equal to:

    [font=Arial][size=2]=TimeInterval(S um([howlong]))[/size][/font]
    [font=Arial][size=2][/size][/font]
    [font=Arial][size=2]And replace the Timer Inverval function with the following one:[/size][/font]
    [font=Arial][size=2][/size][/font]
    Code:
     
    [font=Arial][size=2]Function TimeInterval(value As Long) As String
    ' pass in a value in seconds
    Dim secVal As Integer
    Dim minVal As Integer
    Dim hourVal As Integer
    Dim dayVal As Integer
    Dim days As Long
    Dim hours As Long
    Dim mins As Long[/size][/font]
    [font=Arial][size=2][/size][/font] 
    [font=Arial][size=2]	days = 86400
    	hours = 3600
    	mins = 60
    	
    	dayVal = Fix(value / days)
    	value = value - (dayVal * days)
    	hourVal = Fix(value / hours)
    	value = value - (hourVal * hours)
    	minVal = Fix(value / mins)
    	value = value - (minVal * mins)
    	secVal = value
    	
    	TimeInterval = dayVal & ":" & hourVal & ":" & minVal & ":" & secVal
    	
    End Function[/size][/font]
    Originally posted by Rio Liaden
    Now, I'm getting a compile error. May I send you a copy of this database? It is very small, containing only one table, a query and a report.

    Rio

    Comment

    • MMcCarthy
      Recognized Expert MVP
      • Aug 2006
      • 14387

      #17
      Sorry about all the formatting in previous post. It came in with a copy and paste.

      Make control source of your field equal to:

      TimeInterval(Su m([howlong]))

      And replace the Timer Inverval function with the following one:


      Code:
       
      Function TimeInterval(value As Long) As String
      ' pass in a value in seconds
      Dim secVal As Integer
      Dim minVal As Integer
      Dim hourVal As Integer
      Dim dayVal As Integer
      Dim days As Long
      Dim hours As Long
      Dim mins As Long
       
      	days = 86400
      	hours = 3600
      	mins = 60
       
      	dayVal = Fix(value / days)
      	value = value - (dayVal * days)
      	hourVal = Fix(value / hours)
      	value = value - (hourVal * hours)
      	minVal = Fix(value / mins)
      	value = value - (minVal * mins)
      	secVal = value
       
      	TimeInterval = dayVal & ":" & hourVal & ":" & minVal & ":" & secVal
       
      End Function

      Comment

      • Rio Liaden
        New Member
        • Sep 2006
        • 25

        #18
        This is fabulous! The database is just what I needed and I hope that I will be able to show my appreciation for all of the help I was given by helping someone else. I may not be an Access whiz, but there are a number of other programs on which I am SMOKIN'!

        Thanks so much once again!

        Rio

        Comment

        • rickeyn
          New Member
          • Nov 2006
          • 2

          #19
          I tried to use this module and it works great except the minutes and seconds do not come out right. Do you have same problem? Example I have a second value as 15037 and it comes out as 4h10m37s but it should be 4h18m9s, no?

          Comment

          • rickeyn
            New Member
            • Nov 2006
            • 2

            #20
            I think it's me that calculate wrongly. Sorry for confusion.

            Comment

            • Jerry911
              New Member
              • Nov 2007
              • 10

              #21
              I know this thread has been dead for a long time, I just wanted to say thanks!You helped resolve an issue on a report I was developing and was beating my head against the keyboard over.

              Comment

              Working...