formatting a date that is stored as text

G

Guffy9

I have a table with a column that contains dates that are of the dat
type text. They are stored in the format mmddyy, so they appear a
numbers. For example 06/11/2004 would be 061104. Is there an easy wa
to convert these to a date type or at least format them as a date?

I know that I could use:


Code
 
D

Douglas J. Steele

I would recommend adding a new field to your table, and using an Update
query to store the value as a true date, not as text. That gives you the
flexiibility to use it as a date: you can do date arithmetic on it, format
it anyway you want, and so on.

The safest way to convert them to a date is to use the DateSerial function:

DateSerial(mid(
.[column], 5,2), mid(
.[column], 3,2),
mid(
.[column], 1,2))

Note that since you're only using a 2 digit year, you may get some surprises
in terms of how it interprets the year. I believe the default is to treat
numbers between 00 and 29 as being 2000 to 2029, and numbers between 30 and
99 as 1930 to 1999. Depending on what operating system you're using, you can
set this through Regional Settings on the Control Panel.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Guffy9 said:
I have a table with a column that contains dates that are of the data
type text. They are stored in the format mmddyy, so they appear as
numbers. For example 06/11/2004 would be 061104. Is there an easy way
to convert these to a date type or at least format them as a date?

I know that I could use:


Code:
"/" + mid(
.[column], 5,2) AS DateField FROM Table;
 

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