This is a variant, but it does not handle all possible cases, for example
dt1 = 1 Jan 2009
dt2 = 7 Jan 2009
dt3 = 3 Jan 2009
dt4 = 5 Jan 2009
here is overclossing, but your code will return false...
Main Topics
Browse All TopicsWe have date range (just 2 DateTime), we need to know, if this date range is over-crossing next range of 2 date times.
For example, if first 2 Dates are 1 Jan 2009 - 3 Jan 2009, we have to know, is this range is crossing next date 5 Sep 2008 - 4 Mar 2010, or
1 Jan 2009 - 3 Jan 2009 is crossing 2 Jan 2009 - 5 Jan 2009 or
1 Jan 2009 - 7 Jan 2009 is crossing 2 Jan 2009 - 5 Jan 2009 or
How to check this with c#?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Right!
public bool Test()
{
DateTime dt1 = new DateTime( 2009, 1, 1 );
DateTime dt2 = new DateTime( 2009, 3, 1 );
DateTime dt3 = new DateTime( 2008, 9, 5 );
DateTime dt4 = new DateTime( 2010, 3, 4 );
if ( dt1 >= dt3 && dt1 <= dt4 )
return true;
if ( dt2 >= dt3 && dt2 <= dt4 )
return true;
if ( dt1 < dt3 && dt2 > dt4 ) <---- add this check
return true;
return false;
}
Sure, this is correct decision! Thank alb66!
Just to fully complete this topic, the code need to be modified more. Not always we know that dt1 < dt2 and dt3 < dt4, it could be vice versa, the code will fail again!
Also, initially I had thoughts to do this with just if-then conditions, but maybe there are other ways how to check this per-single-line with maybe some specific c# functions.. What do you think?
Business Accounts
Answer for Membership
by: alb66Posted on 2009-09-17 at 01:18:42ID: 25353777
public bool Test()
{
DateTime dt1 = new DateTime( 2009, 1, 1 );
DateTime dt2 = new DateTime( 2009, 3, 1 );
DateTime dt3 = new DateTime( 2008, 9, 5 );
DateTime dt4 = new DateTime( 2010, 3, 4 );
if ( dt1 >= dt3 && dt1 <= dt4 )
return true;
if ( dt2 >= dt3 && dt2 <= dt4 )
return true;
return false;
}