1

I'm trying to get data going back three months for monthly reports. I got to the point where i can get all the data. The problem is that it goes back 3 months based on the current date.

Example: If today is 7th of November it will give me the data up until the 7th of August. I need it to give me the data going back three months but starting from the first of the month.

Example: today is the 7th of November, I'll need the data starting from the 1st of August.

Here is the code I'm using to get the data from three months back:

SELECT * FROM 'closed_wo_journal' WHERE date_time_stamp > CURDATE() - INTERVAL 3 MONTH
Isaac Bennetch
  • 11,830
  • 2
  • 32
  • 43
D.Reed
  • 11
  • 2

2 Answers2

1

The date_trunc function is just what the doctor ordered:

SELECT *
FROM   closed_wo_journal
WHERE  date_time_stamp > DATE_TRUNC('MONTH', CURDATE() - INTERVAL '3 MONTH')
Mureinik
  • 297,002
  • 52
  • 306
  • 350
1

Here is logic to get the first of the month, three months ago:

SELECT j.*
FROM closed_wo_journal j
WHERE j.date_time_stamp >= ( CURDATE() - INTERVAL (1 - DAY(CURDATE()) DAY) ) - INTERVAL 3 MONTH )
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786