0

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
  • 1
    Trivial inaccuracy. %M is not a pattern for 2-digit month number. Commented Jan 21, 2022 at 10:42

1 Answer 1

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.