Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Turning 0800 text to 08:00:00 AM in access 4

Status
Not open for further replies.

B555

Technical User
Feb 7, 2005
36
US
I need help with formating text field like 0800 to a date field like 08:00:00 AM in a access qry. Can anyone help me with this?
 
Couple of questions to make this a cleaner answer. Does the 0800 represent a military time? (I assume it does)

andy

Andy Baldwin

"Testing is the most overlooked programming language on the books!
 
Something like this ?
Format(Left(TextField,2) & ":" & Right(TextField,2), "hh:nn:ss AM/PM")

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Perhaps:
strTime = "0800"
dteTime = Format(TimeSerial(Left(strTime, 2), Right(strTime, 2), 0), "hh:nn:ss AM/PM")
 
I would create a module and put the following function in it

Public Function ConvertMilTime(strec As String) As Date
strec = Left(strec, 2) & ":" & Right(strec, 2)
ConvertMilTime = Format(strec, "Long Time")

End Function

I added the step of converting the received time to a string with the ":" simply for your understanding of how it would work

Then you query would look like this.

SELECT Field1, Field2, ConvertMilTime(Field3) AS MyTime
FROM Table1


Replace as follows
Field 1 and 2 are simply other fields you want in your query.
Field 3 is the name fo the field you want to convert to normal time.
Table 1 is the table to pull the data from.

The only thing I would add to the function is a check at the beginning to account for
1. Nulls - Assume 0001 for one minute past midnight
2. 0000 - which is not a valid time. Maybe add a one to the end to make it also one minute past midnight

Andy



Andy Baldwin

"Testing is the most overlooked programming language on the books!
 
Thanks for all the help! It worked great. B555
 
PHV, I beg to differ 2358, 2359, 2400, 0001.
0000 does not exist in military time. 24 hrs in a day. One minute past midnight would be 0001.



Andy Baldwin

"Testing is the most overlooked programming language on the books!
 
But in VBA, a valid time is from #00:00:00# to #23:59:59# (as in the real life for us in France).
 
Well if he is in France then he should consider that. For the rest of us, 00:00:01 or 00:00:00:01 (one second past midnight) would be the starting point of a 24 hour day. No military in the world that I have worked with represents any time of 00:00:00. France may be different since I have never had the opprotunity to work with the French military.

The only reason it works in VBA is due to lazy programming on the part of MS (imagine that) in developing their functions.

Andy.

Andy Baldwin

"Testing is the most overlooked programming language on the books!
 
There must be a lot lazy people ...
The ANSI standard for DateTime columns:
DATE values are represented according to the Gregorian calendar and TIME
values are represented according to the 24 hour clock. The inclusive value
limits for the DATETIME fields are as follows:[tt]
YEAR 0001 to 9999
MONTH 01 to 12
DAY 01 to 31 (upper limit further constrained by MONTH and YEAR)
HOUR 00 to 23
MINUTE 00 to 59
SECOND 00 to 59.999999999[/tt]
 
I second that. Military time is equivalent to European time, which uses 23:59 as the last minute of the day and 00:00 as midnight.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top