java - How to exclude date stored in database to a range? -


i have table "holidays" in database, contains range of days when it's holidays, defined 2 column : start & end.

holidays (id, name, start, end) 

now, if have in input, 2 dates (from & to), i'd list dates not in holidays.

suppose holidays 2012/06/05 2012/06/20, , request :

  1. from=2012/06/01, to=2012/06/10 ; result 01, 02, 03, 04
  2. from=2012/06/01, to=2012/06/22 ; result 01, 02, 03, 04, 21, 22
  3. from=2012/06/15, to=2012/06/22 ; result 21, 22

but can't figure out how list of "opened" days without hitting database every days requested in range from->to.

how do?

thanks help!

there many solutions, pretty depends on how many entries have in database , how many requests do. if making lot of request, can thing this:

-> create boolean array determine if day holiday or not;    first element points predefined date (e.g. 1.1.2012),     second element 2.1.2012, etc. -> initialize array 0 -> each holiday   -> make loop initialized holiday start date ,      expression each pass: current date = holiday start date + 1 day     -> covert current date index (number of days since start date - 1.1.2012)     -> set array[index] 1 

now should have simple array containing 0 non-holiday day , 1 holiday day

for each query (request) do

-> loop goes request start date request end date    -> convert current date index (number of days since 1.1.2012)    -> check if array[index] 0 or 1 

but keep in mid, solution ok many query (requests). if have first part every request, solution not make sense , better write sql query.


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -