timestamp or int in mysql |
Which is better?
I am making my own user auth lib - and want to wite last activity. Which is better to use?
Might depend on how you want to use it. Using int, it may be a bit easier and faster to compare values in certain circumstances. For example, you want to see if a certain interval has passed since the last login.
PHP Code: if($last_login + $check_interval < time()){ ... On the other hand, the mysql DATETIME type is easily used to make a PHP DateTime object. From there it's easy to get a display string formatted just about any way you want. The DATETIME type is handy when you want to automatically capture the last time a record is updated. For instance, consider a user profile where a column is defined like this Code: `last_updated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP will capture the update time without any added code on your part.
Personally, I think if you are using a MySQL database, and you want to store a date/time field, then you should use the MySQL date time fields.
|
Welcome Guest, Not a member yet? Register Sign In |