Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Wich Birthdays for two given dates
Message
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00363237
Message ID:
00363292
Vues:
18
Hi,

After second thought I modified the algorithm a little to respect dates within 1 year range.
local lnYearStart, lnYearEnd, ldBeginDate, ldEndDate, lnDiff
lnYearStart=year(dstart)
lnYearEnd=year(dend)
lnDiff=lnYearEnd-lnYearStart

do case

   case lnDiff=0 && Simple case
      SELECT * FROM clients ;
      WHERE between(ctod('^'+str(lnYearStart,4)+'-'+str(MONTH(clients.dob),2)+;
         '-'+str(day(clients.dob),2)),dstart,dend) 

   case lnDiff=1 && More complicated case
     ldStartDate=ctod('^'+str(lnYearEnd,4)+'-01-01')
     ldEndDate=ctod('^'+str(lnYearStart,4)+'-12-31')
      SELECT * FROM clients ;
      WHERE between(ctod('^'+str(lnYearStart,4)+'-'+str(MONTH(clients.dob),2)+;
         '-'+str(day(clients.dob),2)),dstart,ldEndDate) or ;
         between(ctod('^'+str(lnYearEnd,4)+'-'+str(MONTH(clients.dob),2)+;
         '-'+str(day(clients.dob),2)),ldStartDate,dEnd)

    case lnDiff>1 && All cliens
       ** All clients would quilify    

     case lnDiff<0 && Wrong date range
      ** wait window 'Wrong date range'
endcase
>Hi John & George,
>
>It could be easily done.
>
>First assumption: year(dend)-year(dstart)<=1 (within the same year, or, say,
>
>8/11/99 to 5/5/00
>
>Otherwise, all clients with not empty(DOB) quilified.
>
>Let's assume for simplicity (otherwise there could be leap year issue,
>which could be resolved more clever...), that year(dend)=year(dstart)
>
>
>local lnYear
>lnYear=year(dstart)
>SELECT * FROM clients ;
>   WHERE between(ctod(str(month(clients.dob),2)+'/'+str(day(clients.dob),2)+'/'+str(lnYear,4)) ,dstart, dend)
>* Note - better use strict date format and restore date respectively, but I just don't remember this format...
>
>
>
>
>>>
>>>*dob = birthdate, dstart = initial date, dend = final date
>>>
>>>SELECT * FROM clients ;
>>>   WHERE MONTH(clients.dob) >= MONTH(dstart) AND ;
>>>         MONTH(clients.dob) >>         DAY(clients.dob) >= DAY(dstart) AND ;
>>>         DAY(clients.dob) >>
>>
>>Gonz,
>>
>>Won't work if the day number returned by DAY() for the dstart variable is larger than the value returned by DAY(dend).
>>
>>I haven't given this much thought, but the first thing that comes to mind is, unfortunately, a UDF.
>>SELECT * FROM clients;
>>  WHERE DateRange(clients.dob, dstart, dend)
>>
>>FUNCTION DateRange
>>  * VFP 6.0 required
>>  LPARAMETERS tDOB, tdStart, tdStop
>>
>>  LOCAL llresult, lnmonth, lnday, ldthisdate
>>  lnmonth = MONTH(tDOB)
>>  lnday = DAY(tDOB
>>  ldthisdate = DATE(YEAR(DATE()), lnmonth, lnday)
>>  llresult = BETWEEN(ldthisdate, tdStart, tdStop)
>>  RETURN llresult
>>ENDFUNC
I'm not sure if this can even be done without the UDF. 'Course, haven't really given it a lot of thought.< g >
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform