Reputation: 1164
I'm trying to remember the syntax to change a date field into a string. I know I'm close but not 100% correct. Here is what I'm using so far: TO_CHAR(FIELD_NAME)
. I'm using an Access database. The error I'm getting is: undefined expression
. Any help would be very much appreciated.
Upvotes: 1
Views: 5126
Reputation: 1606
Use either CStr(dateField)
or Format(dateField)
to convert.
Additionally you can add parameters to Format()
to show it in a different format, such as:
Format(dateField, "general date") 9/12/2010
Format(dateField, "long date") Monday, September 12, 2011
Upvotes: 3
Reputation: 52645
Given that you're using MS Access and its a date field you're probably not just looking to convert to string but to also format the Date. If that is indeed the case you'll want the Format function
SELECT Format ([DateCreate], "yyyy/mm/dd") AS Foo
FROM MSysObjects;
Upvotes: 1
Reputation: 8804
I assume SQL Server as you're questions in the past are .NET Questions.
Use CONVERT http://msdn.microsoft.com/en-us/library/ms187928.aspx
Upvotes: -1
Reputation: 46047
You can use the CONVERT function, like this:
CONVERT(VARCHAR, DateField, 100)
Here's a link that shows the different date formats you can use:
http://www.sql-server-helper.com/tips/date-formats.aspx
Upvotes: -1