Storing Durations vs Displaying Durations (1 Viewer)

hokiewalrus

Registered User.
Local time
Today, 10:52
Joined
Jan 19, 2009
Messages
50
I have a table that stores time worked by number of minutes. I want to display those times for editing, but of course I don't want to show the user a number of minutes, I want to show him times.

But then I also want him to be able to type in a new time in HH:MM format and then store it back as a number of minutes.

So, if 480 is stored in the table, 8:00 would be displayed, which he can change to 8:30 and subsequently 510 would be stored in the table.

I would pull out the times manually and update them myself using the afterupdate property, but he is choosing employees from a subform that is a list of all employees, and I don't know of any event that fires when you choose a new record from a continuous form.
 

DCrake

Remembered
Local time
Today, 15:52
Joined
Jun 8, 2005
Messages
8,626
I use a table that stores both the times and the durations. I use fucntions to convert mins to time and vice versa. See same of a capture screen used.
 

Attachments

  • timesheet.JPG
    timesheet.JPG
    73.4 KB · Views: 88

DCrake

Remembered
Local time
Today, 15:52
Joined
Jun 8, 2005
Messages
8,626
Here are a few conversions

Code:
Function TimeToMins(Anytime As String) As Integer
If Len(Anytime) = 8 Then
    Anytime = Left(Anytime, 5)
End If
If Len(Anytime) <> 5 Then
    Exit Function
End If

    
If Anytime = "" Then Exit Function
    TimeToMins = (Val(Left(Anytime, 2)) * 60) + Val(Mid(Anytime, 4, 2))
End Function


Code:
Function MinsToTime12(AnyMins As Long) As String
Dim H As Long
Dim M As Long
Dim nTime As String
Dim AmPm As String

    H = Int(AnyMins / 60)
    M = AnyMins - (H * 60)
    If AnyMins > 720 Then
        AmPm = "pm"
        H = H - 12
    Else
        AmPm = "am"
    End If
    If AnyMins = 720 Then
        nTime = "12 noon"
    Else
        nTime = IIf(H = 0, "12", H) & " " & Format(M, "00") & AmPm
    End If
    
MinsToTime12 = nTime

End Function

Code:
Function MinsToTime24(AnyMins As Long) As String
Dim H As Long
Dim M As Long
Dim nTime As String

    H = Int(AnyMins / 60)
    M = AnyMins - (H * 60)
    nTime = Format(H, "00") & ":" & Format(M, "00")
MinsToTime24 = nTime
End Function
 

hokiewalrus

Registered User.
Local time
Today, 10:52
Joined
Jan 19, 2009
Messages
50
Thanks for the tip, I ended up storing both the "time" as well as the duration in minutes in my table.

Storing time durations seems like such a common need I can't believe there isn't a more elegant way to do it, but at least it works now. Thanks!
 

Users who are viewing this thread

Top Bottom