Click here to Skip to main content
15,897,334 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two fields for dates start date & end date ( say for policy).. I have to select the range in between those dates and does not allow user to enter the date in between that range for the next time..
e.g.:
if user have entered start date as 02/09/2010
and end date as 31/07/2011
then when next time he used to enter start date again for his policy it must not be in previous range..
1.
start date: 05/07/2002
end date : 09/12/2004

2.
start date: 10/12/2005
end date : 16/03/2007

3.
start date: 25/03/2010
end date : 31/07/2011

suppose these are the three records in db..now for the 4th record the range which user going to select must not be in any of previous ranges..so how should i select new range???
Posted
Updated 13-Sep-11 0:41am
v2
Comments
Herman<T>.Instance 13-Sep-11 6:19am    
what is your exact problem?
CodingLover 13-Sep-11 6:26am    
So what is your question?

1 solution

The simplest solution is just to check whether the proposed range clashes with any of the existing ranges, and reject it if so. Something like
SQL
select id, startdate, enddate from ranges where (@startdate > startdate and @startdate < enddate) or (@enddate > startdate and @enddate < enddate)

@startdate and @enddate are parameters (pulled from the UI) for the proposed new range, startdate and enddate are column names. If any rows are returned then they are ranges which clash with the proposed new one, and you should construct an error message explaining what the clashes are.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900