Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Help with Date Calculation
Message
De
20/09/1999 10:46:16
 
 
À
20/09/1999 09:55:57
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00266686
Message ID:
00266710
Vues:
14
>For each month in a year, I need to generate a weekly schedule based on our week of operation. Our work week [almost always] starts on Friday EXCEPT the 1st of the month, in which case the 1st of the month is the WeekBeginning; and [almost always] ends on Thursday EXCEPT the last day of the month, in which case the last day of the month is the WeekEnding.
>
>In addition to the above exceptions, the first or last work week of the month cannot consist of more than 10 days or less than 3 days.
>
>Can someone please help me find the WeekBeginning and WeekEnding?

Ok, let's hope I've understood your problem correctly! :-)

Try this. The parameters are the year and the month of the schedule you're creating. I hope I've explained enough...
LPARAMETERS lnYear, lnMonth

LOCAL ldDate, lnWeekNo, ldLastOfMonth

CLEAR

&& Find the first of the month
ldDate = DATE(lnYear, lnMonth, 1)
ldLastOfMonth = GOMONTH(ldDate, 1) - 1

lnWeekNo = 1
DO WHILE ldDate < ldLastOfMonth
    ? "Week " + ALLTRIM(STR(lnWeekNo)) + " begins " + DTOC(ldDate) + "..."

    && Weeks must be at least 3 days
    ldDate = ldDate + 2	&& Only + 2 because the current day
                        && counts too!

    && Find the next Thursday
    DO WHILE DOW(ldDate) <> 5	&& 5 = Thursday
        ldDate = ldDate + 1
    ENDDO

    && Ok, so ldDate is a Thursay now.
    && Now we must check if the next week will have at
    && least 3 days
    IF ldLastOfMonth - ldDate < 3
        && We must include the last days...
        ldDate = ldLastOfMonth
    ENDIF

    ? "Week " + ALLTRIM(STR(lnWeekNo)) + " ends on " + DTOC(ldDate)
    ?

    ldDate = ldDate + 1
    lnWeekNo = lnWeekNo + 1
ENDDO
Hope this helps!
Sylvain Demers
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform