I'm doing a search on a table in my database that needs to return all the data that was created in the current month (I'll run a cron on the last day of the month at 11:00 PM). I have in my table a created_at
field that stores the date entered in the base record.
What I did was the following:
SELECT *
FROM minha_tabela
WHERE created_at >= date_add(last_day(date_sub(curdate(), interval 1 month)), interval 1 day)
AND created_at <= last_day(curdate());
It's working, but I'd like to know if I should leave anyway or if there is any better way to do it, thinking about performance and maintenance.