Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Birthdays this week
Message
 
 
To
19/03/2009 22:33:25
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01389309
Message ID:
01389865
Views:
36
I tested mine and Sergey's solutions. Sergey's was a bit quicker (though it's not a serious test, I didn't restart between tests), but it didn't return Feb. 29th
PRIVATE test

ldStart = DATE(2006,12,31)
ldEnd = DATE(2007,3,3)

lnMonth1 = month(ldStart)
lnDay1 = day(ldStart)
lnSeconds = SECONDS()
IF YEAR(ldStart) = YEAR(ldEnd)
	lnDiff = ldEnd - ldStart

	select dDOB from Patients where dDOB is not null and dDOB <> {} and dDOB ;
	between date(year(dDOB),lnMonth1,lnDay1) and (date(year(dDOB),lnMonth1,lnDay1) + lnDiff) ;
	ORDER BY dDOB INTO CURSOR curTest nofilter
ELSE
	lnMonth2 = month(ldEnd)
	lnDay2 = day(ldEnd)

   	select dDOB from Patients where dDOB is not null and dDOB <> {} and ;
   	(dDOB between date(year(dDOB),lnMonth1,lnDay1) and date(year(dDOB),12,31) ;
	OR dDOB between date(year(dDOB),1,1) and date(year(dDOB),lnMonth2,lnDay2)) ;
	ORDER BY dDOB INTO CURSOR curTest nofilter
ENDIF
=MESSAGEBOX(SECONDS() - lnSeconds)
BROWSE FOR day(dDob) = 29 AND MONTH(dDob) = 2
lnSeconds = SECONDS() 

SELECT dDOB FROM Patients WHERE dDOB is not null and dDOB <> {} and ;
			(DATE( YEAR( ldStart ), MONTH( dDob ), DAY( dDob ) ) BETWEEN ldStart AND ldEnd ;
		OR ;
			DATE( YEAR( ldEnd), MONTH( dDob ), DAY( dDob ) ) BETWEEN ldStart AND ldEnd) INTO CURSOR cTest nofilter
			
=MESSAGEBOX(SECONDS() - lnSeconds)

BROWSE FOR day(dDob) = 29 AND MONTH(dDob) = 2

*_cliptext = test
>>Yes, I think I understood myself this as well.
>>
>>We need to write conditional code, unfortunately.
>>
>>If no span, use my code as is
>>
>>If there is a span, use
>>
>>select dDOB from Patients where dDOB is not null and dDOB <> {} and dDOB ;
>>between date(year(dDOB),lnMonth1,lnDay1) and (date(year(dDOB),12,31)  and dDOB between(date(year(DOB),1,1) and date(year(DOB),lnMonth2, lnDay2);
>>ORDER BY dDOB INTO CURSOR curTest nofilter
>
>Here's my unnecessarily complicated solution, just for kicks:
>
>ldStart = DATE(2008,12,28)
>ldEnd = ldStart+6
>
>lnMonth1 = MONTH(ldStart)
>lnDay1 = DAY(ldStart)
>
>lnMonth2 = MONTH(ldEnd)
>lnDay2 = DAY(ldEnd)
>
>IF YEAR(ldStart)=YEAR(ldEnd)
>	SELECT DISTINCT YEAR(ddob) AS nYear, {} AS dStart, {} AS dEnd ;
>		FROM patients INTO CURSOR crsYears READWRITE
>	REPLACE ALL dStart WITH DATE(nYear, lnMonth1, lnDay1);
>		,	dEnd WITH DATE(nYear, lnMonth2, lnDay2)
>
>ELSE
>	SELECT DISTINCT YEAR(ddob) AS nYear, {} AS dStart, {} AS dEnd ;
>		FROM patients INTO CURSOR crsYears1 READWRITE
>	SELECT nYear, DATE(nYear, lnMonth1, lnDay1) AS dStart, DATE(nYear, 12, 31) AS dEnd;
>		FROM crsYears1 ;
>	UNION SELECT nYear, DATE(nYear, 1, 1) AS dStart, DATE(nYear, lnMonth2, lnDay2) AS dEnd;
>		FROM crsYears1 ;
>		INTO CURSOR crsYears READWRITE
>ENDIF
>
>SELECT ddob FROM patients;
>	JOIN crsYears ON BETWEEN(ddob, dStart, dEnd)
>
>
>Tested once each way, worked. It's basically the same as the one with right(dtos(ddob),4) that's been around already, but may come handy if some additional things may be needed for each year (which things, I don't see, but then I'm not standing that high to see far at the moment :).
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform