The cleanest way to do this is in MySQL using DATE_SUB (or DATE_ADD depending on your goals). For instance:
SELECT DATE_SUB(NOW(), INTERVAL 1 HOUR)
Similarly, you can replace “1 HOUR” with other things, such as “1 DAY” or “1 MINUTE,” etc. I always prefer to make date comparisons at the database level, since presumably the dates are stored in a common format and clockwise offset.
source
share