Format as Date

S

Sam

Hi all
I have a table which stores a date like so: 06012004 (today UK). How can i convert this to a date
Many thank
Sam
 
A

Allen Browne

Create a query into this table.

Type an expression such as this into the Field row in query design:
DateSerial(Right([d], 4), Mid([d], 3, 2), Left([d], 2))

That assumes the text date is in a field named "d".

If you are trying to write the date to a true Date/Time field, change the
query to an Update query (Update on Query menu), and place the expression in
the Update row under your real date field. Then run the query.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

How can i convert this to a date?
 
S

Sandra Daigle

You could use the dateSerial Function:

Dim myDate As Date
Dim datefld As String
datefld = "06012004"

myDate = DateSerial(Right(datefld, 4), Mid(datefld, 3, 2), Left(datefld, 2))
Debug.Print myDate

Just replace datefld with a reference to the field or control that contains
the existing date. You can use this in a query or in VBA depending on what
you are planning to do with the converted value.
 

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