Dates in examples (The Yii Blog Tutorial) are stored in DB as integers.
I think it isnt best practice. I wont to store dates in DATETIME format.
But formatting date by php function date() with hardcoded date format in model when i wont to store data isnt best practice too coz some DBMS may use different date format.
What is best way to store date to DB in DATETIME format using CActiveRecord?
I’m just starting to dig in with Yii, and liking it so far. Haven’t really committed to either of the proposed solutions yet for dates, but have a few questions:
First, does this mean that every time I set a date before writing it to MySQL (using the Save operation), I must first convert it to the correct format?
Secondly, is it not strange that this would be set by default in the MySQL provider configuration section, so that the framework could instantiate and work with dates in the "preferred" format by default?
Third, Jonah, where does best practice dictate you put utility code like that? Does it live in its own file? Some place special in the directory structure?
Follow-up for posterity, I was trying to utilize this method and getting odd results. I had to change the dbDateFormat string as follows (note the i instead of m for minutes):
'params'=>array(
'dbDateFormat'=>'Y-m-d H:i:s'
)
Now, every time I write to the (MYSQL) database, it looks like this:
I personally put it under protected/components, but you can put it anywhere you like as long as the directory is set to auto-include or you manually include it each time