How do you set a default value for a MySQL Datetime column?
In SQL Server it\'s getdate()
. What is the equivalant for MySQL? I\'m using MySQL 5.x if tha
MySQL (before version 5.6.5) does not allow functions to be used for default DateTime values. TIMESTAMP is not suitable due to its odd behavior and is not recommended for use as input data. (See MySQL Data Type Defaults.)
That said, you can accomplish this by creating a Trigger.
I have a table with a DateCreated field of type DateTime. I created a trigger on that table "Before Insert" and "SET NEW.DateCreated=NOW()
" and it works great.
I hope this helps somebody.