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

Inverse String to Time

Status
Not open for further replies.

orna

Programmer
Apr 2, 2002
314
IL
Hi,
I import a text file into a table and have a problem,
the time field (4 digits) refuses to be inserted as a date/time field, so I define it as a text and i'd like
to transfer the data to other table that define the field as date/time.
I'm looking for a function to inverse the field
to a time field and can't find.

Any help with the import or the inverse is appreciated
 
Try using the CDate function:

For example, CDate("12:00") returns 12:00:00 PM
 
Thanks for answering

When i use CDate([txtField]) in a query, i get a date.
If the text field is "1432" or "14:43" it gives the date 02/12/1903
 
I can understand 1432 not showing correctly, but 14:43 should. In fact I created a quick form with one text box. In the AfterUpdate event of the text box, I put the following code:

Private Sub txtField_AfterUpdate()

MsgBox CDate(txtField)

If (IsDate(txtField)) Then
MsgBox "IsDate"
Else
MsgBox "Not IsDate"
End If


End Sub

If I put 1432 in, it displays "12/2/1903" and "Not IsDate".
If I put 14:43 in, it displays "2:43:00" and "IsDate".
 
I have tried it at home and it works just fine.

Thanks
 
I'h just realized why it did'nt work for me.
In my table the field is 4 digits and the input musk is 00:00 so the ":" is not a character, if you type it
it works, so I changed the query :
CDate(Left([txtField],2) & ":" & Right([txtField],2))
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top