I was reading over an article that shows some really good information and benchmarks about how well the three different MySQL date/time storage options perform.
MySQL DATETIME vs TIMESTAMP vs INT performance and benchmarking with MyISAM
While reading the article you start to get the idea that using ints are just a waste and you should instead go with MySQL Datetime or Timestamp column types.
However, towards the end of the article he does one more test not using MySQL functions and you suddenly see that straight INT's are 2x as fast as the two MySQL options when searching by unix timestamps.
So it suddenly dawned on me - duh, what do PHP apps all use? time()! Almost every php application bases their logic off of the Unix Epoch. Which means that most queries for results in a certain time start off based on time() and then are converted to work with MySQL's fields.
This leaves me with the following:
Unix Timestamps stored as INT's are
faster, take less space, and work
natively with PHP's time() based
calculations.
MySQL Date types are more suited to
operations and logic from the MySQL
side.
For the time being both Unix And
MySQL Timestamps only work until
2037 which means that you must use a
datetime field for larger dates in
the future.
MySQL commands like date = NOW()
can lag when
using replication causing data inconsistencies.
So applying this to real life we see that answer
that these results given that most really DBA's would use a better engine like PostgreSQL - is there arny
However, most apps that would be to the level of using DB logic would probably go with PostgreSQL. Which means that all the rest of us programmers only use MySQL for a storage tank for our data (you know it's true) which makes keeping the fields as small, fast, UNIX INT's seem like it is actually the best option.
So what do you guys think?
Are timestamps really more suited to PHP apps than the MySQL date fields?
Copyright License:
Author:「Xeoncross」,Reproduced under the CC 4.0 BY-SA copyright license with link to original source & disclaimer.
Link to:https://stackoverflow.com/questions/3315508/are-mysql-datetime-and-timestamp-fields-better-for-php-apps-then-unix-timestamp