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!

Converting a text field to a date field

Status
Not open for further replies.

cabletek

Technical User
Oct 11, 2002
14
US
I have a field that was imported from a text file that has dates in it. The problem is that it is in the following format: DDMMyyyy and displayed like 11Oct2002 (single digit days displays like 1Oct2002). Because there is no delimiter, it will not import as a date field so it has to be a text field. So how do I convert it to a date field?
 
You'll have to split it...

Function SplitMyWrongField(StrValue)

If Len(StrValue)< 9 Then
SplitMyWrongField = Format(Left(StrValue,1),&quot;00&quot;) & &quot; &quot; _
& Mid(StrValue, 2, 3) & Right(StrValue, 4)
Else
SplitMyWrongField = Left(StrValue,2) & &quot; &quot; _
& Mid(StrValue, 3, 3) & Right(StrValue, 4)
End If

End Function

This would split your string into something like:
01 Oct 2002

HTH
[pipe]
Daniel Vlas
Systems Consultant
danvlas@yahoo.com
 
I assume this has to be done with a Module? I new to programming!
 
Yes, paste the code into a module, then save the module by any name you want except for the function name
Then use the function as if it were built-in. For instance, in a select query insert anew field and:

FieldName: SplitMyWrongField(YourField)

Run the query and...voila...

Good luck

[pipe]
Daniel Vlas
Systems Consultant
danvlas@yahoo.com
 
The script work partially, it splits the day & month but leaves the month/year together (10Oct2002 to 10 Oct2002)??? Ralph Solomon
Comcast Cable Communications
ralph_solomon@cable.comcast.com
 
Oops...quite right...forgot to include a space...

If Len(StrValue)< 9 Then
SplitMyWrongField = Format(Left(StrValue,1),&quot;00&quot;) & &quot; &quot; _
& Mid(StrValue, 2, 3) & Right(StrValue, 4)
Else
SplitMyWrongField = Left(StrValue,2) & &quot; &quot; _
& Mid(StrValue, 3, 3) & &quot; &quot; & Right(StrValue, 4)
End If

Guess it's fixed now...

[pipe]
Daniel Vlas
Systems Consultant
danvlas@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top