I have table (named tasks) with column created_at that, basically, contains UNIX time-stamp.
I need to select only those results that are created in specified time-interval.
Intervals are today, tomorrow, this week and this month.
I think that if I convert time-stamp to YYYY-MM-DD HH:MM:SS format, MySQL can handle it.
Also, I think that I need to use BETWEEN there as well.
So, I pass time-stamp to query and compare (check?) that it’s in the specified interval with time-stamp that is stored in the database. To convert, I need to use FROM_UNIXTIME, right?
How to specify those intervals? Thanks in an advice!
You need to convert UNIX_TIMESTAMP.
Query
You can alter the interval for week, month etc by doing:
MySQL will automatically take the length of months and leap years etc into account.
In the above query MySQL will be able to use an index, speeding things up a lot.
Make sure not to use a function on your column, because in that case MySQL cannot use an index on that field, causing major slowness.
Coding horror, very slow
See: http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-add