我在将一列转换为日期时遇到一些问题。
我希望将'01/02/98'(日、月、年)
转换为'1998-02-01'(年、月、日)
.
以及如何将 '98'
转换为 1998
。
最佳答案
I want this '01/02/98'(day, month, year) to convert to '1998-02-01'(year, month, day). And also how you convert '98' to 1998.
STR_TO_DATE()
处理这两种情况。
https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_str-to-date
这里解释了格式 https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-format
%e 匹配一月中的某一天,数字 (0..31)
%m 匹配月份、数字 (00..12)
%y 匹配年份,数字(两位数)
查询
select str_to_date('01/02/98', '%e/%m/%y');
结果
| str_to_date('01/02/98', '%e/%m/%y') |
| ----------------------------------- |
| 1998-02-01 |
关于MYSQL varchar 迄今为止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53068062/