How to select last 6 months from news table using MySQL
Solution 1:
Use DATE_SUB
.... where yourdate_column > DATE_SUB(now(), INTERVAL 6 MONTH)
Solution 2:
Try this:
select *
from table
where your_dt_field >= date_sub(now(), interval 6 month);
Query reads: give me all entries in table
where the field corresponding to the entry date is newer than 6 months.
Solution 3:
I tried @user319198 answer to display last 6 months (sum of) sales, it worked but I faced one issue in the oldest month, i do not get the sales amount of the whole month. The result starts from the equivalent current day of that month.
Just I want to share my solution if any one interested:-
yourdate_column > DATE_SUB(now(), INTERVAL 7 MONTH)
limit 6
Also it will be great if anyone has better solution for my case J.