A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » General Discussion
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Converting time from number



 
 
Thread Tools Display Modes
  #1  
Old July 9th, 2009, 02:11 AM posted to microsoft.public.access
SF[_4_]
external usenet poster
 
Posts: 18
Default Converting time from number

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


  #2  
Old July 9th, 2009, 03:17 AM posted to microsoft.public.access
James A. Fortune
external usenet poster
 
Posts: 903
Default Converting time from number

SF wrote:
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/micro...d17d7fcefc3ae0

James A. Fortune

  #3  
Old July 9th, 2009, 06:01 AM posted to microsoft.public.access
John W. Vinson
external usenet poster
 
Posts: 18,261
Default Converting time from number

On Wed, 08 Jul 2009 22:17:16 -0400, "James A. Fortune"
wrote:

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 W. Vinson [MVP]
  #4  
Old July 9th, 2009, 11:35 PM posted to microsoft.public.access
James A. Fortune
external usenet poster
 
Posts: 903
Default Converting time from number

John W. Vinson wrote:
On Wed, 08 Jul 2009 22:17:16 -0400, "James A. Fortune"
wrote:


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)


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

  #5  
Old July 10th, 2009, 01:52 AM posted to microsoft.public.access
John W. Vinson
external usenet poster
 
Posts: 18,261
Default Converting time from number

On Thu, 09 Jul 2009 18:35:34 -0400, "James A. Fortune"
wrote:

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 W. Vinson [MVP]
  #6  
Old July 10th, 2009, 05:38 AM posted to microsoft.public.access
James A. Fortune
external usenet poster
 
Posts: 903
Default Converting time from number

John W. Vinson wrote:
On Thu, 09 Jul 2009 18:35:34 -0400, "James A. Fortune"
wrote:


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.


Good idea. That's very clean.

James A. Fortune

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 02:46 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.