SQL日期格式转换?[dd.mm.yy 到 YYYY-MM-DD]
是否有 mySQL 函数将日期从格式 dd.mm.yy 转换为 YYYY-MM-DD?
is there mySQL function to convert a date from format dd.mm.yy to YYYY-MM-DD?
例如,03.09.13 ->2013-09-03.
推荐答案
由于您的输入是 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.
相关文章