mysql datetime转换 时间戳_将MySQL datetime转换为时间戳

时间:2025-01-29 08:07:31

我试图将datetime转换为时间戳,但是mysql给我警告,并且转换的值是错误的。这里是SQL查询

UPDATE table1 A, table2 B SET B.date_added=UNIX_TIMESTAMP(STR_TO_DATE(A.date_added, '%M %d %Y %h:%i%p')) WHERE =;

警告

+---------+------+--------------------------------------------------------------------------+

| Level | Code | Message |

+---------+------+--------------------------------------------------------------------------+

| Warning | 1411 | Incorrect datetime value: '2011-06-11 20:29:02' for function str_to_date |

+---------+------+--------------------------------------------------------------------------+

结果

+---------------------+---------------------+

| date_added | date_added |

+---------------------+---------------------+

| 2012-02-23 06:12:45 | 2012-12-23 19:08:33 |

+---------------------+---------------------+

我也尝试了以下查询,但在时间戳字段中显示0000-00-00 00:00:00。

UPDATE table1 A, table2 B SET B.date_added=UNIX_TIMESTAMP(A.date_added) WHERE =;