Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

A slightly complex date question

New Here ,
Aug 21, 2008 Aug 21, 2008
Hello,

I have a series of date ranges, for example:

08/02/2008-08/04/2008
07/06/2007-07/10/2007
06/05/2006-06/12/2006


The user enters another set of dates:
08/01/2008-08/04/2008

I need to make sure that the range of dates they enter do not overlap with any of the dates mentioned above. The one that the user entered would conflict with (1) above and should return an error.

If they enter another date like:

01/01/1999-02/15/2009

This should also return an error because this date conflicts with ALL of the date ranges above. I would appreciate any help on this issue.
509
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 21, 2008 Aug 21, 2008


I leave it to you to parse the data entry into the dates, but here's how to check for overlap:


<cfset date1_start= "02/01/2008">
<cfset date1_end= "02/10/2008">

<cfset date2_start= "02/11/2008">
<cfset date2_end= "03/01/2008">

<cfif date1_start LTE date2_end AND date1_end GTE date2_start>
<cfset x= "conflict">
<cfelse>
<cfset x= "no conflict">
</cfif>

<cfoutput>#x#</cfoutput>

cheers,
fober
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 21, 2008 Aug 21, 2008
That wouldn't work. What if the dates were:

<cfset date1_start= "02/01/2001">
<cfset date1_end= "02/10/2009">

<cfset date2_start= "02/11/2008">
<cfset date2_end= "03/01/2008">

This would pass your code, but I want this to be unacceptable because the date range includes the dates that are common in both, and thus should yield a conflict.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Aug 21, 2008 Aug 21, 2008
Wouldn't changing LTE and GTE to LT and GT take care of your "problem"?

Phil
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Aug 21, 2008 Aug 21, 2008
quote:

Originally posted by: paross1
Wouldn't changing LTE and GTE to LT and GT take care of your "problem"?

Phil


No:

I need to check for date overlaps.

08/14/2008-08/20/2008

And I enter 08/15/2008-8/17/2008, this should yield false, because this date range has dates that overlap. If I enter 02/07/2007-02/09/2009, it should also yield false, and so should 08/13/2008-08/15/2008, and 08/17/2008-08/22/2008.

All of them are invalid dates and should not be allowed.

Maybe I am explaining the issue improperly. Basically, no single day within the range I enter should overlap with any single day within the existing date range.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 21, 2008 Aug 21, 2008
range1 = date1 - date2
range2 = date3 - date4

if (
(date3 lte date1 and date4 gte date1)
or
(date3 lte date2 and date4 gte date2)
)

you have a conflict
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Aug 21, 2008 Aug 21, 2008
On Thu, 21 Aug 2008 19:44:52 +0000 (UTC), Dan Bracuk wrote:

> range1 = date1 - date2
> range2 = date3 - date4
>
> so if either date3 or date4 is between date1 and date2 you have a confict,
> right?

Or if date3 is less than date1, and date4 is greater than date2.

--
Adam
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 21, 2008 Aug 21, 2008
Hi,
My example should work correctly with any dates, and should clearly indicate if there is any overlap.

I checked your sample dates with the code I have provided, and it correctly shows a conflict.

cheers,
fober

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 25, 2008 Aug 25, 2008
LATEST
Hi,
I just checked Dan's code and it is not correct. It doesn't cover the case where range2 is within range1.

cheers,
fober
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources