I have a column called submit_timestamp which holds a UNIX_TIMESTAMP(), what I want to do now is do a SELECT query and within the WHERE clause ensure the submit_timestamp equals or is within X number of days.
(Demonstration purposes only):
SELECT id
FROM submissions
WHERE submit_timestamp = 'EQUALS OR IS WITHIN X NUMBER OF DAYS FROM submit_timestamp'
AND id = 2
All help appreciated.
Thanks.
Compute the two times you want to compare to in your application before you construct the query. All programming languages will have a function to give you the current timestamp (i.e.
time()in PHP). To get “X days from now”, add 60*60*24*X seconds to the timestamp.Now you’re just comparing integers. Unlike Johan’s solution, MySQL will be able to use an index on the column for the comparisons.