Possible Duplicate:
Datetime vs Timestamp?
I have a Mysql table, which has a column add_date
. It tracks the date/time when the record was added to the database.
Queries based on this table:
Which would be better in this case - unix timestamp or datetime?
Right now I'm using both, but since the table will have millions of records over time, having both columns may affect the size of the database.
Unix timestamp seem to be better for conversion to 2 hours
ago format in PHP and also it is timezone independent. But datetime has better readability and making a query for a particular date/time/year seems easier.
Your suggestion?
When you have the choice, I'd say go for mySQL dates.
You won't have to take care of date range issues
You can easily query time spans using mySQL's date functions (BETWEEN(), DATE_ADD
etc.)
Date related queries will be much faster, especially when you have millions of records, because you won't have to use FROM_UNIXTIME()
which can be expensive in large queries
It's child's play to convert DATE fields into UNIX timestamps when necessary.