imperium2335
imperium2335

Reputation: 24122

MySQL get everything up to the last day of the last month

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

Answers (2)

Karthik Appigatla
Karthik Appigatla

Reputation: 156

jobs.creationDate < LAST_DAY(NOW() - INTERVAL 1 MONTH);

Upvotes: 2

StudyOfCrying
StudyOfCrying

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

Related Questions