Monday, March 12, 2012

How to return date formated like (yyyy/mm/dd)

Hi everybody

Exemple of query
SELECT DT_FIELD FROM TABLE_NAME

DT_FIELD
-------
2001-12-20 00:00:00 --This format is not right

The query must return like that
DT_FIELD
-------
2001-12-20 --This is the good format

I try this function datePart, Convert and cast but is not right

ThankOriginally posted by ericjean
Hi everybody

Exemple of query
SELECT DT_FIELD FROM TABLE_NAME

DT_FIELD
-------
2001-12-20 00:00:00 --This format is not right

The query must return like that
DT_FIELD
-------
2001-12-20 --This is the good format

I try this function datePart, Convert and cast but is not right

Thank|||Thank everybody

I can do like this
SELECT convert(varchar(10),DT_FIELD,103) FROM TABLENAME|||FYI for others having the same issue - the convert function has a style parameter which allows for various datetime formats.

No comments:

Post a Comment