SQL日期格式转换? [dd.mm.yy到YYYY-MM-DD] [英] SQL date format convert? [dd.mm.yy to YYYY-MM-DD]
问题描述
是否有mySQL函数将日期从格式dd.mm.yy转换为YYYY-MM-DD?
例如 03.09 .13 - >由于您的输入是<$ c形式的字符串,因此
STR_TO_DATE
: STR_TO_DATE(myVal, '%d。%m。%y')
然后,您可以使用格式化字符串 DATE_FORMAT
:
$ b $ pre $ DATE_FORMAT(STR_TO_DATE(myVal,'%d。%m。% y'),'%Y-%m-%d')
请注意,年份 STR_TO_DATE
和%Y
%y (小写字母y >(大写Y)在 DATE_FORMAT
中。小写版本为两位数年份,大写字母为四位数字年份。
is there mySQL function to convert a date from format dd.mm.yy to YYYY-MM-DD?
for example, 03.09.13 -> 2013-09-03
.
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')
Then you can format it back to a string using DATE_FORMAT
:
DATE_FORMAT(STR_TO_DATE(myVal, '%d.%m.%y'), '%Y-%m-%d')
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.
这篇关于SQL日期格式转换? [dd.mm.yy到YYYY-MM-DD]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!