[futurebasic] Re: [FB] oldest/newest dates

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : February 2001 : Group Archive : Group : All Groups

From: Jay Reeve <jktr@...>
Date: Thu, 22 Feb 01 23:50:01 -0600
>I'm trying to set the oldest and newest dates from a series of random dates
>in mm/dd/ccyy format. FN setTransDateMinMax below seems to set the right min
>and max but I'm not sure that my logic is right or would cover all
>eventualities. Also, I'd like to speed this up, if possible...
>
Michael,

I think your logic is okay, but if you are really looking for max speed, 
I would do something like this. It is designed to operate on an array 
gTransDateArray() of date strings (STR15), terminated with an empty 
string. (This could just as easily be an XREF@ array.)

This FN relies completely on the dates being formatted exactly as 
"mmxddxccyy" (the dividers don't matter). If you can guarantee (or 
arrange) that, this will process your list in no time.

The speed comes mainly from not calling VAL or DateToSeconds repeatedly.

I have assumed you are using FB^3. This would have to be done with peeks 
in FBII. I have not tested this, but I am fairly confident of the logic.

 0"0
 =J= a  y
  "

dim gOldestDate&,gNewestDate&
dim gTransDateArray(1000) as str15
end globals

clear LOCAL
LOCAL FN setTransDateMinMax
'~'6
dim as ptr oldPtr,testPtr,newPtr
DIM @ dateRec.14
dim as str15 oldDate, newDate

increment = sizeof(gTransDateArray(0))
testPtr   = @gTransDateArray(0)
oldPtr    = @oldDate
newPtr    = @newDate
oldDate   = gTransDateArray(0)'Set oldest and newest to first date in 
array
newDate   = gTransDateArray(0)
testPtr  += increment

while testPtr.0` = 10'Is this a date string?
if testPtr.7& > oldPtr.7& then "checkNewer"' year
if testPtr.7& < oldPtr.7& then "foundOlder"
if testPtr.1% > oldPtr.1% then "checkNewer"' month
if testPtr.1% < oldPtr.1% then "foundOlder"
if testPtr.4% < oldPtr.4% Then "foundOlder"' day
"checkNewer"
if testPtr.7& < newPtr.7& then "nextLoop"' year
if testPtr.7& > newPtr.7& then "foundNewer"
if testPtr.1% < newPtr.1% then "nextLoop"' month
if testPtr.1% > newPtr.1% then "foundNewer"
if testPtr.4% >=newPtr.4% then "nextLoop"' day
"foundNewer"
newDate;12 = testPtr     :goto "nextLoop"
"foundOlder"
oldDate;12 = testPtr
"nextLoop"
testPtr += increment
wend

dateRec.day%     = val(mid$(oldDate,4,2))
dateRec.month%   = val(left$(oldDate,2))
dateRec.year%    = val(right$(oldDate,4))
call DateToSeconds (dateRec,gOldestDate&)

dateRec.day%     = val(mid$(newDate,4,2))
dateRec.month%   = val(left$(newDate,2))
dateRec.year%    = val(right$(newDate,4))
call DateToSeconds (dateRec,gNewestDate&)

end fn