Question

How do I change this format "11/16/2002 12:00:00 PM" to something that MySQL will understand without using PHP?

I've tried SELECT CONVERT('11/03/2002 02:45:33 PM', DATETIME) AS datetime; and I just get NULL

Was it helpful?

Solution

You can use a STR_TO_DATE function -

SELECT STR_TO_DATE('11/03/2002 02:45:33 PM', '%d/%m/%Y %h:%i:%s %p') AS dt;
+---------------------+
| dt                  |
+---------------------+
| 2002-03-11 14:45:33 |
+---------------------+

or

SELECT STR_TO_DATE('11/03/2002 02:45:33 PM', '%d/%m/%Y %r') AS dt;
+---------------------+
| dt                  |
+---------------------+
| 2002-03-11 14:45:33 |
+---------------------+
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top