British dates day/month/year used in examples

Imagine a date of 06/09/2004 (6th Sept 2004)

I need to identify whether the anniversary of this date falls between a
particular date range:

01/08/2008 - 30/09/2008 = TRUE (1st Aug - 30th Sept)
01/06/2008 - 31/08/2008 = FALSE (1st June - 31st Aug)

What is the best way of achieving this, when I don't know how old the
original date might be? Is it just a gomonth(originaldate,12) loop until it
is greater than the end date of the range?

Sincerely

Stephen

Re: Testing the anniversary of a date by Sergey

Sergey
Tue Jul 22 16:28:46 CDT 2008

Hi Stephen,
Try

ldStart = {^2008/08/01}
ldEnd = {^2008/09/30}
ldDate = {^2009/09/06}
? BETWEEN(DATE(YEAR(ldStart), MONTH(ldDate), DAY(ldDate)), ldStart,
ldEnd) ;
OR BETWEEN(DATE(YEAR(ldEnd), MONTH(ldDate), DAY(ldDate)), ldStart, ldEnd)


--
--sb--

VFP MVP

Stephen Ibbs wrote:
> British dates day/month/year used in examples
>
> Imagine a date of 06/09/2004 (6th Sept 2004)
>
> I need to identify whether the anniversary of this date falls between a
> particular date range:
>
> 01/08/2008 - 30/09/2008 = TRUE (1st Aug - 30th Sept)
> 01/06/2008 - 31/08/2008 = FALSE (1st June - 31st Aug)
>
> What is the best way of achieving this, when I don't know how old the
> original date might be? Is it just a gomonth(originaldate,12) loop until it
> is greater than the end date of the range?
>
> Sincerely
>
> Stephen
>
>
>
>

Re: Testing the anniversary of a date by Gene

Gene
Tue Jul 22 18:51:34 CDT 2008

"Stephen Ibbs" <stephen@ibbs.org.uk> wrote:

>British dates day/month/year used in examples
>
>Imagine a date of 06/09/2004 (6th Sept 2004)
>
>I need to identify whether the anniversary of this date falls between a
>particular date range:
>
>01/08/2008 - 30/09/2008 = TRUE (1st Aug - 30th Sept)
>01/06/2008 - 31/08/2008 = FALSE (1st June - 31st Aug)
>
>What is the best way of achieving this, when I don't know how old the
>original date might be? Is it just a gomonth(originaldate,12) loop until it
>is greater than the end date of the range?

Here is some code and a driver. Caveats:

1) I assume that negative anniversaries count (if the date range is
before the date to check anniversaries of).

2) I am not sure how you would handle leap years, so you might have
to patch it for that case.

3) The testing was not thorough.

********** End of Code Segment **********
set talk off
set exact on

? "correct,actual"

testdate={^2008.07.22}
? .t.,anniversaryinrange(testdate,{^2007.01.01},{2007.12.31})
? .f.,anniversaryinrange(testdate,{^2007.01.01},{2007.06.30})
? .t.,anniversaryinrange(testdate,{^2007.07.01},{2007.12.31})
? .t.,anniversaryinrange(testdate,{^2007.03.01},{2007.09.30})
? .f.,anniversaryinrange(testdate,{^2007.09.30},{2008.03.31})

testdate={^2008.02.22}
? .t.,anniversaryinrange(testdate,{^2007.01.01},{2007.12.31})
? .t.,anniversaryinrange(testdate,{^2007.01.01},{2007.06.30})
? .f.,anniversaryinrange(testdate,{^2007.07.01},{2007.12.31})
? .f.,anniversaryinrange(testdate,{^2007.03.01},{2007.09.30})
? .t.,anniversaryinrange(testdate,{^2007.09.30},{2008.03.31})

return

procedure anniversaryinrange
lparameters;
thedate,; && D: the date to check
datelow,; && D: the lower date in the range
datehigh && D: the higher date in the range

* Make sure the range is in the correct order.
if datelow>datehigh
local swap
swap=datelow
datelow=datehigh
datehigh=swap
endif

* If the date range covers a year or more, there must be an
anniversary in
* the date range.
if gomonth(datelow,12)<=datehigh
return .t.
endif

* Chop off the years.
local anniv, rangelow, rangehigh
anniv=right(dtos(thedate),4)
rangelow=right(dtos(datelow),4)
rangehigh=right(dtos(datehigh),4)

if rangelow<=rangehigh && Range is all in calendar one year.
inrange=anniv>=rangelow and anniv<=rangehigh
else && Range spans two calendar years.
inrange=anniv>=rangelow or anniv<=rangehigh
endif

return inrange

endproc
********** End of Code Segment **********

Sincerely,

Gene Wirchenko

Computerese Irregular Verb Conjugation:
I have preferences.
You have biases.
He/She has prejudices.

Re: Testing the anniversary of a date by Christof

Christof
Wed Jul 23 00:30:27 CDT 2008

Hi Stephen,

BETWEEN( RIGHT(DTOS(originaldate),4), RIGHT(DTOS(date1),4),
RIGHT(DTOS(date2),4) )

This expression is optimizable with an index on RIGHT(DTOS(originaldate),4).

--
Christof