Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Help with Date Calculation
Message
De
20/09/1999 12:31:25
 
 
À
20/09/1999 11:56:28
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00266686
Message ID:
00266770
Vues:
26
>Thank you for your response. You had the right idea. However, I failed to mention that this WeekBeginning and WeekEnding calculation is done based on the current system date.
>
>For example, given today's date [9/20/99], the function should return WeekBeginning: 9/17/99 & WeekEnding: 9/23/99. How would you modify your function to do as such?

Hi Carie,

Oh well, even easier! :-) But I found it more convenient to rewrite it all... Glad I can help! I hope you do understand my code; if you don't I'll try to explain it more!
LPARAMETERS ldDate
LOCAL ldStart, ldEnd, ldLastOfMonth

&& You can replace this with ldStart = DATE()
&& and remove the LPARAMETERS line if you want
&& or you can call this procedure with DATE()
&& as the parameter.  I just find it more
&& flexible this way...
ldStart = ldDate

&& Go back to the previous Friday, or first of the month,
&& whichever comes first
DO WHILE DOW(ldStart) <> 6 AND DAY(ldStart) > 1
    ldStart = ldStart - 1
ENDDO

&& Check to make sure there are at least 3 days
&& before, so the previous week will have at
&& least 3 days
IF ldStart - DATE(YEAR(ldStart), MONTH(ldStart), 1) < 3
    && Not enough days, so we must include them
    ldStart = DATE(YEAR(ldStart), MONTH(ldStart), 1)
ENDIF


&& Similar process for ldEnd
&& Same thing about the LPARAMETER statement...
ldEnd = ldDate
ldLastOfMonth = GOMONTH(DATE(YEAR(ldEnd), MONTH(ldEnd), 1), 1) - 1

DO WHILE DOW(ldEnd) <> 5 AND ldEnd < ldLastOfMonth
    ldEnd = ldEnd + 1
ENDDO

&& Check to make sure there are at least 3 days
&& in the next week
IF ldLastOfMonth - ldEnd < 3
    && Include them!
    ldEnd = ldLastOfMonth
ENDIF

? "Week is from " + DTOC(ldStart) + " to " + DTOC(ldEnd)
Sylvain Demers
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform