I’m trying to select rows from the last 2 hours. For some reason it doesn’t work. The code syntax looks ok and works when used on other tables, but for some reason when used on table Posts, get rows a lot older than 2 hours.
SELECT * FROM Posts WHERE `Date` > SUBDATE( CURRENT_DATE, INTERVAL 2 HOUR)
Is there any problem with the code? Is there another way to write it? What could be the reason for this?
That’s because you’re using
CURRENT_DATE, you should useNOW()orCURRENT_TIMESTAMPinstead.The problem is that using
CURRENT_DATE, being a date value, the time defaults to00:00:00, so by substracting 2 hours you end up getting22:00:00of the previous day, instead of the last 2 hours…