Unix timestamp vs datetime [duplicate] Unix timestamp vs datetime [duplicate] php php

Unix timestamp vs datetime [duplicate]


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.


I'd go for the mysql formats, just because mysql has a plenty of datetime function, to use which with timestamp will cost you another conversion.

but since the table will have millions of records over time, having both columns may affect the size of the database.

oh my.
are you really concerned in 4 additional megabytes of space?


You can get the best of both worlds by using a unix timestamp and the MySQL from_unixtime() function to convert the result to datetime format where needed.