2
我想將我的數據庫的datetime列轉換爲沒有數據丟失的時間戳。我也跟着這樣的回答: Bulk convert and update datetime column values to UNIX timestamp?mysql - 將datetime列轉換爲時間戳
但是當我想:
UPDATE `members` SET `new_join_date` = UNIX_TIMESTAMP(`join_date`), `new_last_visit` = UNIX_TIMESTAMP(`last_visit`);
我得到這個錯誤:
#1292 - Incorrect datetime value: '1376833381' for column 'new_join_date' at row 1
完全皈依查詢:
ALTER TABLE `members`
ADD COLUMN `new_join_date` TIMESTAMP NULL AFTER `join_date`,
ADD COLUMN `new_last_visit` TIMESTAMP NULL AFTER `last_visit`;
UPDATE `members`
SET `new_join_date` = UNIX_TIMESTAMP(`join_date`),
`new_last_visit` = UNIX_TIMESTAMP(`last_visit`);
ALTER TABLE `members` DROP `join_date`;
ALTER TABLE `members` DROP `last_visit`;
ALTER TABLE `members` CHANGE `new_join_date` `join_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;
ALTER TABLE `members` CHANGE `new_last_visit` `last_visit` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;
但我需要該列爲TIMESTAMP類型不是INT。 – exim
@exim那麼你不能在這些列中以unix格式存儲日期! – alfasin