Skip to content
Advertisement

Comapring DATE_ADD with NOW not working on MySQL

I’ve try to compare an DateTime in MySQL.

The table is to check locked users. For sample, an User will be locked for 1 Day at the DateTime 2020-04-09 14:51:32:

until is the datetime time_created with added days from locked_time.

Here is the Result of entries:

The calculation (time_created with added locked_time with the result 2020-04-10 14:51:32) is correctly. But when i try to compare this value with an current timestamp (like NOW()), no results are available – Whether I use >= or <=:

How can I check if the date is ‘until’ within ‘NOW()`?

Advertisement

Answer

Expressions defined in the SELECT clause are not available in the WHERE clause (the latter is evaluated before the former). You would need to repeat the expression:

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement