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.