Using MySQL should I store time data as an Int which would be the number of milliseconds since midnight, January 1, 1970 UTC or as Timestamp in the database.
I know both have advantages which is the best way to do it?
Using MySQL should I store time data as an Int which would be the number of milliseconds since midnight, January 1, 1970 UTC or as Timestamp in the database.
I know both have advantages which is the best way to do it?
Can't say for sure from standpoint of your PHP code, but storing it in MySQL datetime format opens up all the MySQL date/time functions without having to deal with first converting with FROM_UNIXTIME. Also, timestamps have a limit of the year 2038 - see Why do timestamps have a limit to 2038?
As the comments say, you can convert either way, so it becomes a question of where do you want the most convenience - in your SQL statements, or PHP code.
IMHO, times/dates are not just a number - they have special purposes in our use of them, so storing them as just a number is limiting yourself.
There are a couple of other things to think about when using timestamps in MySQL.
You are (NOT, see EDIT below) only allowed one timestamp column per table in your database
The one cool thing you can do with timestamp columns that you can't do with datetime columns is you can use default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP (again you only get one column that can do this).
Other than that and the other things mentioned already, I think that's the only incentive to use those columns.
EDIT: You can have more than one timestamp column in a table. But, you can only have one DEFAULT CURRENT_TIMESTAMP timestamp per table. Note that if you add a column to a table:
ALTER TABLE table_name ADD COLUMN col_name TIMESTAMP
and there isn't another timestamp column in that table, it implicitly adds that onto the definition. At least on MySQL 5.0.92. See the discussion below.