CActiveRecord dates don't make it to the DB ( always 1970-01-01 )

I’m saving a date on a MySQL table through CActiveRecord.

I’ve tried formatting the date as m/d/yyyy and yyyy-mm-dd , but each time the date that ends up in the database is 1970-01-01.

I tried valid dates, say 5/5/1980 for instance.

Does I18N have anything to do with this?

Is there a way I can look at the SQL query generated when the model saves to the DB, so I can see if there’s an error there? or at least I can try it directly on mysql and see what happens.

I had the same problem, and this is what I came up with…probably not the best, but it’s working at this point…I had to do a ton of checks, with debugging straight to the screen at every step in the code.

First, added this as a parameter in my main.php (for MySQL database):

'dbDateFormat'=>'Y-m-d H:i:s'

Now, when saving to the db, I call this:


I still haven’t gotten the native datetime validation working though…it seems everytime yii tries to convert to the datetime type, you end up with the result you’re seeing.

You can enable loggin of queries in config/main.php. Also enable enableParamLogging in CDbConnection

Great, how do I do that?

in your config/main.php: