time format

  • Thread starter Thread starter David M. Fizer
  • Start date Start date
D

David M. Fizer

Hello,

I would like to have the time displayed as a four digit number on a
report. Example 09:00. As of now it doesn't show the morning hours with
four digits. Can someone help?

Thanks,
David
 
David

Try this

Function test_date()

Dim get_hour As String
Dim get_min As String
Dim time_string As String

get_hour = Hour(Now())

If Len(get_hour) = 1 Then
get_hour = "0" & get_hour
End If

get_min = Minute(Now())

If Len(get_min) = 1 Then
get_min = "0" & get_min
End If

time_string = get_hour & get_min

End Function

The LEN function checks for single digit hours or minutes and inserts an 0
to show 01 to 09 depending on the hour or minute.
 
Thanks for your reply Alan just one more question where do I put this
function?


Thanks again,
David
 
David


If you are using a query, then

1. Create a new module with the following code

note field1 is the field currently used to show the time on your
report.

Function format_time(field1)

Dim get_hour As String
Dim get_min As String
Dim time_string As String

get_hour = Hour(field1)

If Len(get_hour) = 1 Then
get_hour = "0" & get_hour
End If

get_min = Minute(field1)

If Len(get_min) = 1 Then
get_min = "0" & get_min
End If

time_string = get_hour & get_min

End Function

If you want to display the time as 09:00 then use this line
time_string = get_hour & ":" & get_min

2. Save the module as mod_format_time or some other suitable name.

3. In your query change the column with the field1 entry to
field2:format_time(field1) where field2 is any name
there is a semicolon : between field2 and format_time
4. Save your changes

5. On your report change the field1 to field2

Allan Murphy
Email: (e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top