MySQL 日期时间字段:截断了不正确的日期时间值
MySQL datetime filed: Truncated incorrect datetime value
我正在尝试将字符串转换为 mysql 日期时间格式。使用以下格式。但它给出 Truncated incorrect datetime value
消息。
遵循此页面格式https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_str-to-date
如何修复这个功能?
update userdata set validity_start_date=STR_TO_DATE('10/29/2015 2:12 PM','%m/%d/%Y %h:%i');
ERROR 1292 (22007): Truncated incorrect datetime value: '10/29/2015 2:12 PM'
谢谢
您的字符串中有“PM”,但没有为其指定格式代码。
mysql> select STR_TO_DATE('10/29/2015 2:12 PM','%m/%d/%Y %h:%i') as d;
+---------------------+
| d |
+---------------------+
| 2015-10-29 02:12:00 |
+---------------------+
1 row in set, 1 warning (0.00 sec)
mysql> show warnings;
+---------+------+----------------------------------------------------------+
| Level | Code | Message |
+---------+------+----------------------------------------------------------+
| Warning | 1292 | Truncated incorrect datetime value: '10/29/2015 2:12 PM' |
+---------+------+----------------------------------------------------------+
“上午”/“下午”部分使用 %p
:
mysql> select STR_TO_DATE('10/29/2015 2:12 PM','%m/%d/%Y %h:%i %p');
+-------------------------------------------------------+
| STR_TO_DATE('10/29/2015 2:12 PM','%m/%d/%Y %h:%i %p') |
+-------------------------------------------------------+
| 2015-10-29 14:12:00 |
+-------------------------------------------------------+
1 row in set (0.00 sec)
(执行此操作时没有警告。)
我正在尝试将字符串转换为 mysql 日期时间格式。使用以下格式。但它给出 Truncated incorrect datetime value
消息。
遵循此页面格式https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html#function_str-to-date
如何修复这个功能?
update userdata set validity_start_date=STR_TO_DATE('10/29/2015 2:12 PM','%m/%d/%Y %h:%i');
ERROR 1292 (22007): Truncated incorrect datetime value: '10/29/2015 2:12 PM'
谢谢
您的字符串中有“PM”,但没有为其指定格式代码。
mysql> select STR_TO_DATE('10/29/2015 2:12 PM','%m/%d/%Y %h:%i') as d;
+---------------------+
| d |
+---------------------+
| 2015-10-29 02:12:00 |
+---------------------+
1 row in set, 1 warning (0.00 sec)
mysql> show warnings;
+---------+------+----------------------------------------------------------+
| Level | Code | Message |
+---------+------+----------------------------------------------------------+
| Warning | 1292 | Truncated incorrect datetime value: '10/29/2015 2:12 PM' |
+---------+------+----------------------------------------------------------+
“上午”/“下午”部分使用 %p
:
mysql> select STR_TO_DATE('10/29/2015 2:12 PM','%m/%d/%Y %h:%i %p');
+-------------------------------------------------------+
| STR_TO_DATE('10/29/2015 2:12 PM','%m/%d/%Y %h:%i %p') |
+-------------------------------------------------------+
| 2015-10-29 14:12:00 |
+-------------------------------------------------------+
1 row in set (0.00 sec)
(执行此操作时没有警告。)