Now I have a data string like this 2002年05月11日
, I want to convert this string as a unix date timestamp, what should I do to convert this time? I have tried this way:
select STR_TO_DATE("2002年05月11日", "YYYY年MM月dd日")
did not work. Then I tried this:
select STR_TO_DATE("2002年05月11日", "%Y年%M月%d日")
still did not work. what should I do to convert it to date format that could understand by database?
asked Jan 21, 2022 at 9:41
1 Answer 1
Use lower case 'm':
mysql> select STR_TO_DATE("2002年05月11日", "%Y年%m月%d日");
+-----------------------------------------------------+
| STR_TO_DATE("2002年05月11日", "%Y年%m月%d日") |
+-----------------------------------------------------+
| 2002年05月11日 |
+-----------------------------------------------------+
answered Jan 21, 2022 at 20:55
lang-sql
%M
is not a pattern for 2-digit month number.