I use DATETIME to store timestamp. I see Yii 2.0 use INT(11) to store timestamp.
-
which is better for MySQL ?
-
which is easier to "filter" (e.g. GridView, I want to find records that is greater or lesser than a certain date) ?
I use DATETIME to store timestamp. I see Yii 2.0 use INT(11) to store timestamp.
which is better for MySQL ?
which is easier to "filter" (e.g. GridView, I want to find records that is greater or lesser than a certain date) ?
this is a very relative question… but I’d use int (unsigned) simply because unix timestamps are ints.
It also depends on what you want to store. Unfortunately I can’t link to a stackoverflow answer to this topic.
A difference between unix-timestamp and DateTime is, that DateTime represents "just" a date like in calendar and the timestamp is an exact point in time. The difference is important when you handle timezones.
Like Andrew McWhite said… it depends what you want to achieve.
Google for "datetime vs timestamp" to get a understanding what the differences are.
Then you can decide better what you want to use.
I personally use timestamps for all created_at / updated_at attributes.
Regards