Answer the question
In order to leave comments, you need to log in
MySQL - how to know if a new hour has started?
How can MySQL tell if a new hour has started?
And then the option:
DATE(last_limit_error) = CURDATE() AND HOUR(last_limit_error) < HOUR(NOW())
OR
DATE(last_limit_error) < CURDATE()
Answer the question
In order to leave comments, you need to log in
If the condition is checked at least once an hour, then HOUR(last_limit_error) != HOUR(NOW()) is sufficient.
Perhaps if I understand the task correctly, you just need to keep the date and time of the end of the hourly limit in the table, and each time you send a request, compare it with the current date and time, that's all. Additional precomputations are not required, and therefore the load on the server is reduced.
Unless of course you need to prolong it every hour, then it's better to use the method described by @shogunkub
I don't understand people like you. It is working? Works. Does the task? Fulfills. So why are you trying to apply perfectionism to the simplest task?
The fact that the request turned out to be ugly is normal. The DB is not designed for such things. This should be a question for you: why are you asking the base what time it is? Do you have krona (task scheduler)? Or you don't know about event in MySQL?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question