How to set default value for DATE column (not DATETIME / TIMESTAMP) for current date?

NOTE. The question is the DATE type, not the Datetime or Timestamp.

How to change date column type to use current date by default? I have seen many examples for datetime, but not for date. I tried:

ALTER TABLE `accounting` ALTER `accounting_date` SET DEFAULT CURRENT_DATE;
ALTER TABLE `accounting` CHANGE `accounting_date` `accounting_date` DATE NOT NULL DEFAULT CURRENT_DATE;

I also tried using CURDATE (), NOW (), CURRENT_DATE () ...

+4
source share
1 answer

You probably can't set a default value for the 'date' data type in mysql. You need to change the type to timestamp or datetime.

Perhaps you look at this similar question.

Invalid default value for 'Date'

EDIT:

5.6.5 datetime , . :

CREATE TABLE foo (
    `creation_time`     DATETIME DEFAULT CURRENT_TIMESTAMP,
    `modification_time` DATETIME ON UPDATE CURRENT_TIMESTAMP
)

: http://optimize-this.blogspot.com/2012/04/datetime-default-now-finally-available.html

+4

All Articles