SQL check if expiry date is within 30 days


I am trying to make a invoice system.
Im trying to make a cronjob to automatically run a php script but I dont know the right SQL query.

if expirydate in table is less than 30 days run script…

I tried this:
SELECT id FROM data_myservices WHERE DATEDIFF(day, Now(), expires) < 30

First Im trying to check how many. then I am going to make a script for each ID.

Assuming you posted this in the desired forum section, that’s not the MySql datediff() syntax. You would have been getting an sql error. MySQL :: MySQL 8.0 Reference Manual :: 12.7 Date and Time Functions

Or just compare it like this:

mysql> SELECT id FROM data_myservices WHERE expires > now() - INTERVAL 30 day;
Sponsor our Newsletter | Privacy Policy | Terms of Service