Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Why use int instead of datetime or timestamp in the 'users' table?
  • I was trying to check the datatype of the column to display date format instead of integer value and found out that the 'created_at' and 'updated_at' column was defined as int instead of datetime. So, I wonder if there is any particular issue for doing this?
  • You use int when you store a unix timestamp instead of a datetime format.
  • Thank you very much for the reply. But I'm still not very clear about the difference between MySQL timestamp and unix timestamp.
    Since MySQL has timestamp datatype, why use int to store unix timestamp? Is there any implication for doing this or it's just a matter of personal preference? Your explanation would really help or you can point me to the appropriate reference sources. Thanks.
  • 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.
  • PHP works with Unix timestamps internally, they can be turned into PHP's DateTime objects or Fuel's Date objects without conversion. MySQL timestamps are more usefull if you are planning on using MySQL's date/time related SQL functions, if all your manipulation takes place in PHP Unix timestamps are better.
  • Thanks a lot. It's clear now :)

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion