Calculates the 1st, 2nd, 3rd, 4th, 5th weekday of any month from the passed arguments.

Syntax

JSV_nthDay(nth, expWD, expM, expY)

Prototype

n/a

Returns

The function nthDay returns the date of the nth weekday within the month of the year. If the date exceeds the last date of the month, nthDay returns 0.

Parameters

The nthDay function uses the following arguments.

Argument Description
nth Value from 1 to 5. This value represents the 1st, 2nd, 3rd, 4th, or 5th weekday of interest.
expWD Weekday of interest. Valid weekday values include:
  • 0 - Sunday
  • 1 - Monday
  • 2 - Tuesday
  • 3 - Wednesday
  • 4 - Thursday
  • 5 - Friday
  • 6 - Saturday
expM Month of interest. Valid months include:
  • 0 - January
  • 1 - February
  • 2 - March
  • 3 - April
  • 4 - May
  • 5 - June
  • 6 - July
  • 7 - August
  • 8 - September
  • 9 - October
  • 10 - November
  • 11 - December
expY Year of interest.

Remarks

n/a

Dependencies

JSV_isLeapYear, JSV_toDate

Example

The following lines of code

var i = 0;
var today = new Date(), 
    year = JSV_getFullYear(today),
    month = today.getMonth(),
    day = today.getDay();
document.write( "For " + monthNames[month] + " " + year + ":");
document.write( "The 1st " + dayNames[day] + " is " + JSV_nthDay(1,day,month,year) );
document.write( "The 2nd " + dayNames[day] + " is " + JSV_nthDay(2,day,month,year) );
document.write( "The 3rd " + dayNames[day] + " is " + JSV_nthDay(3,day,month,year) );
document.write( "The 4th " + dayNames[day] + " is " + JSV_nthDay(4,day,month,year) );
document.write( "The 5th " + dayNames[day] + " is " + JSV_nthDay(5,day,month,year) );

produce