How to add current date to an existing table?

How to add current date to existing table for each row?

+3
source share
2 answers
ALTER tableName ADD (DateField DATE);
UPDATE tableName SET DateField = CURDATE();

If you also want the current time, change Dateto DATETIMEand CURDATE()toNOW()

Note. If you are using php (as noted in the question), it might be faster to change 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;
+5
source
UPDATE `table` set `date` = NOW();
+1
source

Source: https://habr.com/ru/post/1793314/


All Articles