13

I have the string 04/04/2012 04:03:35 AM. How can I convert it and insert into a table? Field type is datetime.

6
  • 1
    it`s return empty string Commented May 10, 2012 at 17:23
  • cast ('04/04/2012 04:03:35 AM') as datetime? Commented May 10, 2012 at 17:24
  • Post the Insert SQL you are using. Commented May 10, 2012 at 17:25
  • Downvoters care to explain? It's a perfectly valid question. Commented May 10, 2012 at 17:38
  • @eggyal Please refer to the stackoverflow.com/questions/how-to-ask, i am sure there is a clause there that say provide example of what you have tried first and make sure you search for your answer prior to asking, such as stackoverflow.com/questions/3296725/parse-date-in-mysql Commented May 10, 2012 at 22:11

1 Answer 1

23

You need to use STR_TO_DATE():

STR_TO_DATE('04/04/2012 04:03:35 AM', '%d/%m/%Y %r')

Or, better yet, present your literal in a format MySQL expects (e.g. YYYY-MM-DD HH:mm).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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.