JDelage
JDelage

Reputation: 13682

Should I convert Unix time stamp in an "hour" time stamp?

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

Answers (2)

Marin Sagovac
Marin Sagovac

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

perh
perh

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

Related Questions