更新MySQL中的'ZERO'DATETIME值

时间:2011-05-03 17:24:54

标签: mysql sql datetime

尝试将DATETIME值为00:00:00的mysql行更新为新日期。

UPDATE wp_posts SET post_date = FROM_UNIXTIME(UNIX_TIMESTAMP('2011-05-02'))
and post_date_gmt = FROM_UNIXTIME(UNIX_TIMESTAMP('2011-05-02')) 
WHERE post_date = 0 LIMIT 100

如果有数千个0值,则会更新0000-00-00 00:00:00行。

1 个答案:

答案 0 :(得分:1)

UPDATE wp_posts SET post_date = FROM_UNIXTIME(UNIX_TIMESTAMP('2011-05-02')),
       post_date_gmt = FROM_UNIXTIME(UNIX_TIMESTAMP('2011-05-02'))
       WHERE post_date ="0000-00-00 00:00:00"