/** * Returns the day of the month(1-31) of Last Occurrence of a day (1-sunday,2-monday etc.) in a given month. * * @param TheDayOfWeek Ordinal value representing the desired day of the week (1-sunday,2-monday etc.) * @param TheMonth Ordinal value representing the month (1-January, 2-February, etc.) * @param TheYear The year. * @return Returns a numeric value. * @author Ken McCafferty (mccjdk@yahoo.com) * @version 1.0, August 22, 2001 */ function GetLastOccOfDayInMonth(TheDayOfWeek,TheMonth,TheYear) { //Find The Number of Days in Month Var TheDaysInMonth=DaysInMonth(CreateDate(TheYear,TheMonth,1)); //find the day of week of Last Day Var DayOfWeekOfLastDay=DayOfWeek(CreateDate(TheYear,TheMonth,TheDaysInMonth)); //subtract DayOfWeek Var DaysDifference=DayOfWeekOfLastDay - TheDayOfWeek; //Add a week if it is negative if(DaysDifference lt 0){ DaysDifference=DaysDifference + 7; } return TheDaysInMonth-DaysDifference; }