CodeIgniter Forums
timestamp or int in mysql - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: timestamp or int in mysql (/showthread.php?tid=69152)



timestamp or int in mysql - glorsh66 - 10-14-2017

Which is better? 
I am making my own user auth lib - and want to wite last activity.
Which is better to use?


RE: timestamp or int in mysql - dave friend - 10-14-2017

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.


RE: timestamp or int in mysql - PaulD - 10-14-2017

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.