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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
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.