Im trying to create a cron job involving aggregating emails sent within a period.
I need to perform a query such as
SELECT count(*) from table where action_time < NOW();
How would I go about this?
I’m aware of CURDATE() and CURTIME() but I need to compare both the time and date so the action is performed in the exact minute after the event, CURTIME would mean at midnight i would get an issue.
Edit: CURTIME() only includes the time so a job in the db with action time 23:59:59 wouldn’t be run at 00:00:59 – a minute later (since the latter is not greater than the first)
I can use datetime or timestamp but what would I use as a function to compare (I use NOW() above but that doesn’t work)
Update: I tried using
SELECT count(*) from table where UNIX_TIMESTAMP(action_time) < UNIX_TIMESTAMP(NOW());
and it works 🙂
I tried