Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Week by Month
Message
From
27/12/2006 06:22:32
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP SP2
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01180294
Message ID:
01180431
Views:
22
Idared to expand it to make it more generic
one can E.G. get the second tuesday of the month:
but it is not so compact anymore
* Program....:  NumDowOfMonth.prg
* Version....:
* Author.....: Sergey Berezniker , mod. Peter A. Cortiel
* Date.......: 12/27/06
* Compiler...: Visual FoxPro 09.00.0000.3504 for Windows for Windows
* Abstract...: original code by Sergey
*				I added to make it generic
*				to say eg 2nd Monday of Month
*               if only param 1 and 2 are given it defaults to 4th friday             
* 			..:
* Changes....:

*FUNCTION FourthFridayOfMonth(tnYear, tnMonth,4,"FRI")
LPARAMETERS tnYear, tnMonth , lnWeekNum , nFirstDayOfWeek
LOCAL lnDOW , lnX1

nFirstDayOfWeek=EVL(nFirstDayOfWeek,"")
lnWeekNum =EVL(lnWeekNum ,4)

DO CASE
	CASE nFirstDayOfWeek="MON"
		lnX1 = 3

	CASE nFirstDayOfWeek="TUE"
		lnX1 = 4

	CASE nFirstDayOfWeek="WED"
		lnX1 = 5

	CASE nFirstDayOfWeek="THU"
		lnX1 = 6

	CASE nFirstDayOfWeek="FRI"
		lnX1 = 7

	CASE nFirstDayOfWeek="SAT"
		lnX1 = 1

	CASE nFirstDayOfWeek="SUN"
		lnX1 = 2

	OTHERWISE
		lnX1 = 7
ENDCASE

lnDOW = DOW(DATE(tnYear, tnMonth, 01), lnX1 )

TRY 
	rtn=DATE(tnYear, tnMonth, 7 - lnDOW + 1 + (lnWeekNum -1)*7)
        ** added try endtry if for example the 5th friday does not exist

CATCH
	rtn={}

FINALLY

ENDTRY



RETURN rtn
>
>FUNCTION FourthFridayOfMonth(tnYear, tnMonth)
>LOCAL lnDOW
>lnDOW = DOW(DATE(tnYear, tnMonth, 01), 7)
>RETURN DATE(tnYear, tnMonth, 7 - lnDow + 1 + 3*7)
>
>* or one-liner
>FUNCTION FourthFridayOfMonth(tnYear, tnMonth)
>RETURN DATE(tnYear, tnMonth, 7 - DOW(DATE(tnYear, tnMonth, 01), 7) + 1 + 3*7)
>
>
>>
>>I need to get the four friday date from each month.
>>
>>Example:
>>getFourFridayFromMonth(year = 2007, month = 01) && return Date(2007,01,26)
>>getFourFridayFromMonth(year = 2007, month = 02) && return Date(2007,02,23)
>>getFourFridayFromMonth(year = 2007, month = 03) && return Date(2007,03,23)
>>getFourFridayFromMonth(year = 2007, month = 04) && return Date(2007,04,27)
>>getFourFridayFromMonth(year = 2007, month = 05) && return Date(2007,05,25)
>>getFourFridayFromMonth(year = 2007, month = 06) && return Date(2007,06,22)
>>getFourFridayFromMonth(year = 2007, month = 07) && return Date(2007,07,27)
>>getFourFridayFromMonth(year = 2007, month = 08) && return Date(2007,08,24)
>>getFourFridayFromMonth(year = 2007, month = 09) && return Date(2007,09,28)
>>getFourFridayFromMonth(year = 2007, month = 10) && return Date(2007,10,26)
>>getFourFridayFromMonth(year = 2007, month = 11) && return Date(2007,11,23)
>>getFourFridayFromMonth(year = 2007, month = 12) && return Date(2007,12,26)
Peter Cortiel
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform