1

I am not able to process my date format from inputs of dates like Jan-05-1975 , Kindly let me know what is wrong with following sql query. I want the format from the input to be in dd-mm-yyyy

Select STR_TO_DATE ('Jan-05-1975','%e-%b-%Y')
OR
Select DATE_FORMAT ('Jan-05-1975','%e-%b%-Y')
4

1 回答 1

2

由于您最初是在传递一个字符串,因此您应该先将其转换为日期,然后再转换为您想要的格式。这同时使用了STR_TO_DATE()then DATE_FORMAT()

Select Date_Format(STR_TO_DATE('Jan-05-1975','%b-%d-%Y'),'%d-%m%-%Y');

请参阅带有演示的 SQL Fiddle

STR_TO_DATE您当前格式的字符串转换为日期值,然后DATE_FORMAT将其转换为首选格式dd-mm-yyyy

于 2012-12-13T10:30:13.897 回答