Welcome Guest, Not a member yet? Register   Sign In
timestamp or int in mysql
#1

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

(This post was last modified: 10-14-2017, 06:33 AM by dave friend.)

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.
Reply
#3

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.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB