Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Need last day of month, 2nd wednesday ...stuff like that
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00844758
Message ID:
00844767
Views:
24
Yeeees!

>>I need some fancy date functions....
>>First, I need to know the last day of a givin month...
>>
>>Then I also need to be able to determine the 1st, 2nd, 3rd, 4th, last [monday, tuesday, whatever] day of the month.
>>In other words, the user would select the 4th Thurday of Oct, 2003 - I need a way to know that is Thurday Oct 23, 2003.
>>
>>This seems like something that would be a fairly common need - has anyone got anything like this already?
>>
>>Thanks....
dThirdMonday = fDateFind( "Monday", 3 )
>If Empty( dThirdMonday ) Then
>	Return .F.
>Endif
>
>*************************************************************************
>Function fDateFind( cDayOfWeek, iDesiredInstance, iYear, iMonth ) As Date
>*************************************************************************
>	If PCount() < 2
>		Error "Insufficient parameters passed to fDateFind()."
>		Return {}
>	EndIf
>
>	Local iDayOfWeek As Integer, cAllWeekDays As String
>	cAllWeekDays = Cdow( Date() )
>	For iDayOfWeek = 1 To 6
>		cAllWeekDays = cAllWeekDays ;
>						+ "," ;
>						+ Cdow( Date() + iDayOfWeek )
>	Next iDayOfWeek
>
>	*- Validate all parameters.
>	If Empty( cDayOfWeek ) ;
>		Or IsNull( cDayOfWeek ) ;
>		Or Type( "cDayOfWeek" ) # "C" ;
>		Or Not Proper( AllTrim( cDayOfWeek )) $ cAllWeekDays Then
>		Error "Invalid parameters passed to fDateFind() : cDayOfWeek."
>		Return {}
>	EndIf
>
>	If Empty( iDesiredInstance ) ;
>		Or IsNull( iDesiredInstance ) ;
>		Or Type( "iDesiredInstance" ) # "N" ;
>		Or iDesiredInstance > 5 Then
>		Error "Invalid parameters passed to fDateFind() : iDesiredInstance."
>		Return {}
>	EndIf
>	
>	If PCount() > 2 ;
>		And ;
>		(Empty( iYear ) ;
>		Or IsNull( iYear ) ;
>		Or Type( "iYear" ) # "N") Then
>		Error "Invalid parameter passed to fDateFind() : iYear."
>		Return {}
>	EndIf
>
>	If PCount() > 3 ;
>		And ;
>		(Empty( iMonth  ) ;
>		Or IsNull( iMonth ) ;
>		Or Type( "iMonth " ) # "N") Then
>		Error "Invalid parameter passed to fDateFind() : iMonth ."
>		Return {}
>	EndIf
>
>	Local dResult As Date ;
>		, iMatches As Integer
>
>	cDayOfWeek = Proper( Alltrim( cDayOfWeek ))
>	If Empty( iMonth ) Then
>		iMonth = Month( Date() )
>	EndIf
>	If Empty( iYear ) Then
>		iYear = Year( Date() )
>	EndIf
>
>	dResult = Date( iYear, iMonth, 1 )
>	*- Find first instance.
>	Do While CDow( dResult ) # cDayOfWeek
>		dResult = dResult + 1
>	EndDo
>	*- Add on number of weeks required to get to the desired instance.
>	dResult = dResult + ((iDesiredInstance-1) * 7)
>
>	If Month( dResult ) > iMonth Then
>		*- iDesiredInstance not found, this is possible if looking for the fifth, but only 4 are present.
>		Error "Month does not have iDesiredInstance (" + Transform( iDesiredInstance ) + "), for " + cDayOfWeek
>		Return {}
>	Endif
>	Return dResult
>	EndFunc	&& fDateFind( cDayOfWeek, iDesiredInstance, iYear, iMonth ) As Date.
ICQ 10556 (ya), 254117
Previous
Reply
Map
View

Click here to load this message in the networking platform