MySQL - Find date ranges matching a list of months -
i have several rows in table, each containing start date , end date. user has checkbox each month of year. need determine rows contain date range includes of user's chosen months.
it's easy check start & end months by, example, month(start_date) in ($month_list)
, approach won't match months between 2 dates.
so suppose i'm asking is: there way of obtaining inclusive months date range purely in sql?
i assume want include data rows date range spans or intersects selected periods - in case, i'd shove user selected periods table , fuzzy join, like.....
select distinct at.* a_table at, user_periods at.start_date<=up.end_date , at.end_date>=up.start_date , up.trans_id=$some_var
(the trans_id allows table used multiple operations)
to minimise effort here, user_periods table should have index on start_date , end_date, , similar a_table.
Comments
Post a Comment