You are here

Why Integer instead of datetime in mysql

A MySQL datetime field is quite difficult to manipulate. If you want to do anything with it, you need to either run SQL with datetime functions, which can become quite complex, or retrieve the records and then use PHP code to convert the data. On the other hand, a unix timestamp is just a number, so selections are quick, it easy to do comparisons, etc. Furthermore, Datetime is stored as a string, which takes up more space than an int, and querying is slower, as most RDBMS engines index int's a lot more efficient. And a final concern is portability. Every RDBMS supports int, but DateTime is MySQL specific. If you, your employer or your client ever decides to migrate to another platform, you're in for a code change.


User login