I am trying to select users information from my database but I only want to retrieve those who logged in the last 3 hours
I tried the following :
SELECT * FROM user WHERE last > CURTIME(), INTERVAL 3 HOUR ORDER BY last DESC
But it is not working. I guess I put the INTERVAL function in the wrong place. but I tried many approaches and it is still not working.
How can you fix it? is there a better way than using the CURTIME() function ?
You should be using
NOW(), notCURTIME(), because CURTIME is just the time as a string, without the date. So if it’s 1am, someone who logged in yesterday at 11pm would not be included.