Convert text to date

S

scubadiver

Hello,

I am trying to link to a text file. I was having trouble converting 20011975
into a date/time format but it wasn't working. So I formatted the field as a
text file. I have tried converting this to 20/01/1975 in a query but it comes
out with errors and wierd dates.

I've had a look at the other messages and had a go but no go.

thanks
 
K

Klatuu

Regardless of how your dates are displayed either by formatting or based on
regional settings, all date functions exppect a month day year format. To
convert your string to a date field:

strTextDate = "20011975"
SomeDate = DateSerial(Clng(Right(strTextDAte,4)),
Clng(Mid(strTextDate,3,2)), Clng(Left(strTextDAte,2)))
 
S

scubadiver

Brilliant!

Klatuu said:
Regardless of how your dates are displayed either by formatting or based on
regional settings, all date functions exppect a month day year format. To
convert your string to a date field:

strTextDate = "20011975"
SomeDate = DateSerial(Clng(Right(strTextDAte,4)),
Clng(Mid(strTextDate,3,2)), Clng(Left(strTextDAte,2)))
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top