Change date in access query

davidcantor
3StarLounger
Posts: 247
Joined: 05 Nov 2012, 19:40

Change date in access query

Post by davidcantor »

I need to change a date field from yyyymmdd to mmddyyyy using an access query, can anyone help me please?

User avatar
HansV
Administrator
Posts: 78540
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Change date in access query

Post by HansV »

If it is a real date/time field, the format is just a matter of display - whether a date is displayed as 20131203 or as 12032013, the underlying value stored in the table is the same.
If it is a number field or a text field, however, it does matter.
So:
1) What is the data type of the field?
2) What type of field do you want to convert to - should it remain the same or not?
Best wishes,
Hans

davidcantor
3StarLounger
Posts: 247
Joined: 05 Nov 2012, 19:40

Re: Change date in access query

Post by davidcantor »

it is stored as text and would like to convert it to Date/time format using an update query, thanks

User avatar
HansV
Administrator
Posts: 78540
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Change date in access query

Post by HansV »

Let's say the current field is named TextDate.
If you want to convert it to a date/time field in a select query, you can use

RealDate: DateSerial(Left([TextDate],4),Mid([TextDate],5,2),Right([TextDate],2))

Set the Format property of this field to the format that you want.

If you want to convert it to a date/time field in the table, you must create this field before running the update query, and set its Format property to the format that you want.
In the update query, add the new field to the query grid.
In the Update to: line, enter

DateSerial(Left([TextDate],4),Mid([TextDate],5,2),Right([TextDate],2))
Best wishes,
Hans