views:

110

answers:

3

Using Access 2003

Date Column datatype is text

Table1

Date

20090528
20090529
20090530
20090502
20090504

Expected Output

28-May-2009
29-May-2009
30-May-2009
02-May-2009
04-May-2009

...,

How to make a query for the Expected Output Date format?

A: 

CDate should do what you want...

Irfy
Please explain how CDate() can convert a string of the form "20090504" into a date.
David-W-Fenton
+3  A: 

As VBA code - you could wrap it as a function

Dim strMyDate As String
Dim dteDate As Date

strDate = "20090528"
dteDate = DateSerial(Left(strDate, 4), Mid(strDate, 5, 2), Right(strDate, 2))
MyStr = Format(dteDate, "dd-mmm-yyyy")
Debug.Print MyStr

As a Data type in a Table - If you append the data to a table where the field is Date/Time formatted then you can specify the format on the Form / Table i.e. at output time.

heferav
It is best not to use a User Defined Function (UDF), if you don't need to.
Remou
+1  A: 

I find that Cdate does not work for me.

Format(DateSerial(Left(Field1, 4), Mid(Field1, 2, 2), Right(Field1, 2)), "dd-mmm-yyyy")
Remou