how to add current date to existing table?
Ho开发者_运维问答w do I add current date to existing table for each row??
ALTER tableName ADD (DateField DATE);
UPDATE tableName SET DateField = CURDATE();
If you want the current time also, change Date
to DATETIME
& CURDATE()
to NOW()
Note: If you are using php (as tagged in the question) It may be quicker to alter the table with the current time:
$dtFormatted = date("Y-m-d"); //php code
ALTER tableName ADD (DateField DATE DEFAULT '{$dtFormatted}');
ALTER tableName MODIFY DateField DATE DEFAULT NULL;
UPDATE `table` set `date` = NOW();
精彩评论