How to set default MySQL DateTime (not TIMESTAMP) to NOW () or Current_DateTIme?

Possible duplicate:
How to set default value for MySQL Datetime column?

I have a table with a CreatedDate column of a datetime data type and I want to be able to set its default value for the current DateTime, how to do this?

I tried Now () and CurrentTimestamp, but so far no luck !!!

+7
source share
2 answers

You can set a static default value in the table definition.
Therefore, if you do not want to call ALTER TABLE every minute ....

Use trigger:

 DELIMITER $$ CREATE TRIGGER bu_table1_each BEFORE UPDATE ON table1 FOR EACH ROW BEGIN SET new.datefield = NOW(); END $$ DELIMITER ; 

See: http://dev.mysql.com/doc/refman/5.5/en/triggers.html

+5
source

I do not think you can do this with DateTime.

See: How to set the default value for a MySQL Datetime column?

+1
source

All Articles