[英]Can't change date format SQL
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].我在表的列中有当前日期格式 [DD_MM_YYY],并希望将其更改为 [YYYY_MM_DD]。 Can't seem to figure out the correct syntax.
似乎无法弄清楚正确的语法。
This one should do for date fields:这应该用于日期字段:
SELECT DATE_FORMAT(NOW(), '%Y-%m-%d');
You can use the convert function in sql.您可以在 sql 中使用转换 function。
SELECT CONVERT (data_type(length)),Date, DateFormatCode)
To convert in this format [YYYY_MM_DD] if the date format is in varchar
:如果日期格式为
varchar
,则以这种格式转换 [YYYY_MM_DD] :
Select CONVERT(varchar,column_name,23)
If you are using Exasol, you can use to_date()
:如果您使用的是 Exasol,则可以使用
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')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.