Converting text to dates

G

GLS

Hi

I have inherited an Access 97 database which has the dates
in text format eg '20040425'. Changing the data type in
design view deletes all the records. Anyone know how I
can convert these dates from text to date without data
loss.

Thanks

GLS
 
C

Cheryl Fischer

You can add a new field (of Date type) to your table and then do an Update
query to fill it with the date value from your text field. Here is the SQL
for an Update query using the DateValue() function to convert the text to a
true date:

UPDATE [MyTable] SET [MyTable].NewDateField = DateValue(Left([TextField],4)
& "/" & Mid([TextField],5,2) & "/" & Right([TextField],2))


hth,
 
G

GLS

Thanks Cheryl - that worked great.

Much appreciated

GLS
-----Original Message-----
You can add a new field (of Date type) to your table and then do an Update
query to fill it with the date value from your text field. Here is the SQL
for an Update query using the DateValue() function to convert the text to a
true date:

UPDATE [MyTable] SET [MyTable].NewDateField = DateValue (Left([TextField],4)
& "/" & Mid([TextField],5,2) & "/" & Right([TextField],2))


hth,
--

Cheryl Fischer, MVP Microsoft Access
Law/Sys Associates, Houston, TX


GLS said:
Hi

I have inherited an Access 97 database which has the dates
in text format eg '20040425'. Changing the data type in
design view deletes all the records. Anyone know how I
can convert these dates from text to date without data
loss.

Thanks

GLS


.
 

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