Reputation: 24122
I need to get records out of my database where the date stamp on them is before the last day of last month.
I am currently using this:
AND jobs.creationDate <= date_format(NOW() - INTERVAL 1 MONTH, '%Y-%m-'+last_day(NOW() - INTERVAL 1 MONTH))
Which I'm not sure is working or not.
Is their a simpler way of achieving what I want and is what I have used correct (it's very hard to test this in my case).
Upvotes: 0
Views: 353
Reputation: 530
You can find the last day of the prior month with the following:
SELECT LAST_DAY(DATE_SUB(NOW(), INTERVAL 1 MONTH));
Upvotes: 1