Converting time from number

  • Thread starter Thread starter SF
  • Start date Start date
S

SF

Hi,

I was asked to develop a telephone log tracking in access. The base table is
linked to a DBF of the telephoning software. I have a problem displaying the
DURATION and TIME (both save in numeric) into the correct format

TIME = 54120 > How to display into proper time format (eg: 00:00)


SF
 
SF said:
Hi,

I was asked to develop a telephone log tracking in access. The base table is
linked to a DBF of the telephoning software. I have a problem displaying the
DURATION and TIME (both save in numeric) into the correct format

TIME = 54120 > How to display into proper time format (eg: 00:00)


SF

For TIME, in order to change the total number of seconds from midnight
into military time, try:

Public Function SecToMilitary(lngNumberOfSeconds) As String
SecToMilitary = Format(lngNumberOfSeconds \ 3600, "00") & ":" _
& Format(lngNumberOfSeconds \ 60, "00")
End Function

or (to add tenths of a minute):

Public Function SecToMilitary(lngNumberOfSeconds) As String
SecToMilitary = Format(lngNumberOfSeconds \ 3600, "00") & ":" _
& Format(lngNumberOfSeconds \ 60 _
+ Round((lngNumberOfSeconds Mod 60) / 60, 1), "00.0")
End Function

Note: It wouldn't hurt to make sure lngNumberOfSeconds is less than the
number of seconds in a day (60 * 60 * 24 = 86400).

For DURATION, see:

http://groups.google.com/group/microsoft.public.access/msg/e0d17d7fcefc3ae0

James A. Fortune
(e-mail address removed)
 
For TIME, in order to change the total number of seconds from midnight
into military time, try:

Public Function SecToMilitary(lngNumberOfSeconds) As String
SecToMilitary = Format(lngNumberOfSeconds \ 3600, "00") & ":" _
& Format(lngNumberOfSeconds \ 60, "00")
End Function

Or more simply,

DateAdd("s", lngNumberOfSeconds, datefield)
 
John said:
Or more simply,

DateAdd("s", lngNumberOfSeconds, datefield)

I agree that's simpler, but you still need to use the "hh:nn" format if
you want military time. Maybe something like:

Format(DateAdd("s", lngNumberOfSeconds, CDate(0)), "hh:nn")

or the same thing with some other date value since the date part will
not show anyway.

James A. Fortune
(e-mail address removed)
 
I agree that's simpler, but you still need to use the "hh:nn" format if
you want military time. Maybe something like:

Format(DateAdd("s", lngNumberOfSeconds, CDate(0)), "hh:nn")

Sure, or - my preference - just set the Format property of the form or report
textbox.
 
John said:
Sure, or - my preference - just set the Format property of the form or report
textbox.

Good idea. That's very clean.

James A. Fortune
(e-mail address removed)
 
Back
Top