Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Incorrect datetime value for function str_to_date

Tags:

mysql

I can't see what is wrong with this:

mysql> select str_to_date('3/8/2010 12:31:00 AM', '%c/%e/%Y %k:%i:%s %p');
+-------------------------------------------------------------+
| str_to_date('3/8/2010 12:31:00 AM', '%c/%e/%Y %k:%i:%s %p') |
+-------------------------------------------------------------+
| NULL                                                        |
+-------------------------------------------------------------+
1 row in set, 1 warning (0.00 sec)

mysql> show warnings;
+-------+------+---------------------------------------------------------------------------+
| Level | Code | Message                                                                   |
+-------+------+---------------------------------------------------------------------------+
| Error | 1411 | Incorrect datetime value: '3/8/2010 12:31:00 AM' for function str_to_date |
+-------+------+---------------------------------------------------------------------------+
1 row in set (0.00 sec)
like image 226
Clodoaldo Neto Avatar asked Mar 24 '11 22:03

Clodoaldo Neto


Video Answer


1 Answers

%k:%i:%s %p

%k is 24-hour clock, doesn't work with %p (AM/PM). Use %l.

like image 185
bobince Avatar answered Oct 11 '22 17:10

bobince