I have the current date format [DD_MM_YYY] in a column on my table and would like to change it to [YYYY_MM_DD]. Can't seem to figure out the correct syntax.
Asked
Active
Viewed 465 times
3 Answers
0
This one should do for date fields:
SELECT DATE_FORMAT(NOW(), '%Y-%m-%d');

slkorolev
- 5,883
- 1
- 29
- 32
0
You can use the convert function in sql.
SELECT CONVERT (data_type(length)),Date, DateFormatCode)
To convert in this format [YYYY_MM_DD] if the date format is in varchar
:
Select CONVERT(varchar,column_name,23)

Amal K
- 4,359
- 2
- 22
- 44

Tripti Muchhal
- 94
- 2
0
If you are using Exasol, you can use to_date()
:
select to_date(datecoll, 'DD_MM_YYYY')
I would recommend leaving this as a date. But if you want to convert this back to a string:
select to_char(to_date(datecoll, 'DD_MM_YYYY'), 'YYYY-MM-DD')

Gordon Linoff
- 1,242,037
- 58
- 646
- 786