How to generate DATETIME data type for MySQL

there is mySQL data type called DATETIME. I am trying this code to generate the time stamp to save into mySQL, but it doesn’t work. Nothing is saved.


$user->created = date("YYYY-MM-DD HH:MM:SS");

Can you tell me who to create the date and time to save into DATETIME data type in MySQL?

Thank you!

use timestamp, do not use date. so in php u can manage by time()

try this, it will work




$user->created  = new CDbExpression('now()');



Thanks you!