time format

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
 
A

Allan Murphy

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.
 
D

David M. Fizer

Thanks for your reply Alan just one more question where do I put this
function?


Thanks again,
David
 
A

Allan Murphy

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: [email protected]
 
Top