Hello,

I want to check whether one given date range is falling under another range or not.
Is there function for this?
Because when I am calculating this using To and FROM dates , it is taking efficient.
I have to apply separate condition for TO date and FROM date.

Is there any function am unaware of?

I want trying like:

if(($comapare_FROM_Date > $existing_FROM_date && $comapare_FROM_Date < $existing_TO_date) ||
($comapare_TO_Date > $existing_TO_date && $comapare_TO_Date < $existing_TO_date))
echo " is bigger"; // either FROm date falls in between or TO date falls then echo

abviously , above is not satisfying for each conditions.

What do you mean by "falling under another range"?

I guess you could mean does one date range overlap another or does it exist completley within another date range.

Which of these is it that you need?

for example...
I have one range as
a]
from: 09-11-1999
to: 12-01-2001

b] from: 23-01-2001
to: 27-11-2004

so if entered new set as
FROM: 19-01-2001
TO: 25-10-2003
it should not allow me to enter.

I have previous such record as [a] and [b] and I will enter new record which should not OVERLAP any of the present date range

Do you want to check only if one range overlaps another or whether it is completely within as well - ie any of them or just overlap?

one date range comes under another.. completely

Ok so given date range 1 and date range 2

This is pseudo code:

If ((Range1.FromDate > Range2.FromDate And Range1.FromDate < Range2.ToDate) And (Range1.ToDate > Range2.FromDate And Range1.ToDate < Range2.ToDate)) Then
    /* Range 1 falls completley within Range2 */
End If

Hello,
Thanks for solution.
I had applied it too.
It got failed for below case:
EXISTING RECORD:
From Date 2006-05-17
To Date 2007-12-19

I ADDED :
From Date 2007-12-17
To Date 2008-01-26

It is not like next adding record will be only greater that existing one.
it can be past that existing.

For exaple(whichever I came in my mind now) ,
suppose I am adding employment record for employee.
I can add any duration record.
just have to take care that one employemnt record should not came in another

Fighting with now !!! :)
Thanks a lot for your help

Ok so if you want to check whether they overlap OR fall within completley then just use:

If ((Range1.FromDate > Range2.FromDate And Range1.FromDate < Range2.ToDate) Or (Range1.ToDate > Range2.FromDate And Range1.ToDate < Range2.ToDate)) Then
    /* Range 1 falls completley within Range2 or overlaps */
End If

So I just changed the And to an Or