且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

SQL日期格式转换?[dd.mm.yy 到 YYYY-MM-DD]

更新时间:2023-02-26 14:06:30

由于您的输入是 03.09.13 形式的字符串,我假设(因为今天是 2013 年 9 月 3 日)它是 dd.mm.yy.您可以使用 STR_TO_DATE:

Since your input is a string in the form 03.09.13, I'll assume (since today is September 3, 2013) that it's dd.mm.yy. You can convert it to a date using STR_TO_DATE:

STR_TO_DATE(myVal, '%d.%m.%y')

然后您可以使用 DATE_FORMAT:

Then you can format it back to a string using DATE_FORMAT:

DATE_FORMAT(STR_TO_DATE(myVal, '%d.%m.%y'), '%Y-%m-%d')

请注意,年份是 STR_TO_DATE 中的 %y(小写y")和 %Y(大写Y")代码>DATE_FORMAT代码>.小写的版本是两位数的年份,大写的版本是四位数的年份.

Note that the year is %y (lowercase "y") in STR_TO_DATE and %Y (uppercase "Y") in DATE_FORMAT. The lowercase version is for two-digit years and the uppercase is for four-digit years.