Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Finding Sundays
Message
From
12/04/2000 13:09:18
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Miscellaneous
Thread ID:
00358746
Message ID:
00358790
Views:
25
>>>I need to find all Sundays in a given month.
>>>
>>>Thanks and Gog Bless,
>>>S.Dyke
>>
>>
lparameters tnMonth, tnYear
>>ldStart=ctod("^"+str(tnYear,4)+"/"+padl(int(tnMonth),2,"0")+"/"+"01")
>>ldEndDay = gomonth(ldStartDay,1)-day(gomonth(ldStartDay,1))
>>for ix = 0 to day(ldEndDay)
>> ? ldStart+ix, dow(ldStart+ix,2) = 7 && Sunday
>>endfor
Cetin
>
>...and we also have
LPARAMETER tmonth, tyear
>
>LOCAL lddate, lndow
>* Get the first day of the month
>lddate = DATE(tyear, tmonth, 1)
>* Get its DOW() Making sure 1 = Sunday and 7 = Saturday
>lndow = DOW(lddate, 1)
>* Get the first Sunday, if it isn't
>IF lndow # 1
>  lddate = lddate + (8 - lndow)
>ENDIF
>DO WHILE MONTH(lddate) = tmonth
>  ? lddate
>  lddate = lddate + 7
>ENDDO

Hidy George,
IOW you're blaming me for unneccesiraly looping the whole month day by day :-) Well I now code my "other" thought :)
lparameters tnMonth, tnYear
ldStart=ctod("^"+str(tnYear,4)+"/"+padl(int(tnMonth),2,"0")+"/"+"01")
ldEndDay = gomonth(ldStartDay,1)-day(gomonth(ldStartDay,1))
IF dow(ldStart,1) # 1
  lddate = dow(ldStart,1) + (8 - dow(ldStart,1))
ENDIF
for ix = day(lddate)-1 to day(ldEndDay-1) step 7
 ? ldStart+ix, dow(ldStart+ix,2) = 7 && Sunday
endfor
I intentionally prevent date(Y, M, D) for older versions.
PS: This is just to reply to your voice my friend.
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform