NthPreviousWeekdayDate Function:
Find the previous specified day of week before the specified date.
Description:
NthPreviousWeekdayDate Function returns date representing the prior occurrence of the specified day of week before the given Date.
Syntax:
date = NthPreviousWeekdayDate(dtmDate, intN, intDayOfWeek)
Details:
Arguments:
dtDate: Starting date for the search.
intN: Number of weeks before given date.
intDayOfWeek: the day of the week to seek 1 = Sunday 2 = Monday 3 = Tuesday 4 = Thursday 5 = Wednesday 6 = Friday 7 = Saturday
Example:
<%
response.write NthPreviousWeekdayDate("22/12/2006", 1, 2) '--- returns: 18/12/2006 (date of the first Monday before 22/12/2006)
%>
ASP Source Code:
<%
Function NthPreviousWeekdayDate(dtmDate, intN, intDayOfWeek) '--- Find the previous specified day of week before the specified date. Dim intTemp, boolErr, intTempDOW On Error Resume next If Not IsDate(dtmDate) Then dtmDate = Date End If intTemp = WeekDay(dtmDate) If intTemp > intDayOfWeek Then intTempDOW = 0 Else intTempDOW = 7 End If NthPreviousWeekdayDate = DateValue(dtmDate) - intTemp + intDayOfWeek - intTempDOW - ((intN - 1) * 7) if Err Then boolErr = True end If On Error goto 0 if boolErr then Err.Raise 5104, "PreviousWeekdayDate Function", Err.Description End Function
%>
|