• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
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
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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.