I do not like the other two answers because they do not allow the optimizer to use the index on start_date . For this, the functions must be on the current side of the date.
So, I would go for:
where start_date >= date_add(curdate(), interval 1 - day(curdate()) day) and start_date < date_add(date_add(curdate(), interval 1 - day(curdate()) day), interval 1 month)
All date functions are on curdate() , which does not affect the ability of MySQL to use the index in this case.
You can also include a condition on end_date :
where (start_date >= date_add(curdate(), interval 1 - day(curdate()) day) and start_date < date_add(date_add(curdate(), interval 1 - day(curdate()) day), interval 1 month) ) and end_date <= date_add(curdate(), interval 30 day)
This may still use the index.
Gordon linoff
source share