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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert Short Time to 4 Digit Text

Status
Not open for further replies.

doc6

MIS
Feb 12, 2000
8
US
I have an Access 2000 Date/Time Field that is formatted as Short Time. I need to convert it into a 4 digit text field that holds the time without the ":". For example: "21:00" needs to be "2100" or "7:08" needs to be "0708". I need the text field so that i can export it to another progam. Does anyone know how i can do this? Thank you in advance.
 
doc6,

Format(dtmYadda, "hhnn") will give you the response you're looking for. Depending on what you're doing with it you may want to save that value in a string or numeric variable.

Jeremy Wallace
AlphaBetCityDataworks.com
 
Is the hour section always two digit (e.g. 07, or 11, etc.) or does the leading 0 get dropped? If it is always there then you could rewrite the 1rst, 2nd, 4th and 5th characters to another field using Left and Mid functions to build your 4digit number and then export that. Would that help? Build a recordset of the records you want to convert and then start taking apart each value (we'll call it OldStr). Your variable (newStr) could be Left(OldStr,2) which gives you the first two characters plus Mid(OldStr, 3,2) which gives you the 4th and 5th characters. Look under help for Left and Mid functions and also under Recordsets if necessary.
 
Sorry but found my own answer.
Added the following:
hours_field = hour(time_field)
minutes_field = minute(time_field)
if len(hours_field) < 2 then
hours_field = &quot;0&quot; & hours_field
end if
if len(minutes_field) < 2 then
minutes_field = &quot;0&quot; & minutes_field
end if
text_field = hours_field & minutes_field


THanks for the advise everyone
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top