mysql - How do i select all records for the next 3 months including the current one when it turns into a new year -
i trying select every record between current month , next 2 months not able because year changing 2016 2017.
for ex.
i want records november 2016 january 2017.
the current query (shown below) have has worked fine until month because november 2016 + 2 months = jan 2017.
select * datetable month(t2.`end_date`) between month(curdate()) , month(date_add(curdate(), interval 2 month)) , year(t2.`end_date`) = year(curdate()); this returns 0 rows because cannot handle having 2 years, 2016 , 2017.
how go doing this?
this should need, although there number of ways of doing this
select * datetable `end_date` between date_format(now() ,'%y-%m-01') , last_day(date_add(now(), interval 2 month)) the result of query demonstrate dates being generated
select date_format(now() ,'%y-%m-01') from_date, last_day(date_add(now(), interval 2 month)) to_date today generate
from_date to_date 2016-11-01 2017-01-31
Comments
Post a Comment