Reputation: 13682
I'm using PHP and MySQL.
I need to store a unix time stamp each time one of my users accomplish a given action. I only need an hourly detail level. Is there any reason why I shouldn't reduce storage by storing something like (integer)(time()/3600)
instead of the full time stamp? I need to do multiple queries on this time stamp per session per user.
If I save the time stamp as is, I plan to store it as an INT
in MySQL. I'll need to create an index combining userID and time stamp.
If I convert the time stamp into a number of hours, I can store it as a MEDIUMINT
in MySQL.
Upvotes: 0
Views: 163
Reputation: 3982
Generally this will reduce space in a database if you on a table have under 5 millons inserts of timestamp data. In other way you didn't need but for a performance save as unsigned (10) integer in database instead timestamp or date/time. This will be produce faster of indexing and searching a data.
Upvotes: 0
Reputation: 1708
Well. One reason: Unless the timestamp is saved as a string, or we are past year 2038 it will not actually use less space.
Upvotes: 1