Documentation

This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

nweekdate

Date of specific occurrence of weekday in month

Syntax

  • Date = nweekdate(n,Weekday,Year,Month)
    example
  • Date = nweekdate(n,Weekday,Year,Month,Same,outputType)
    example

Description

example

Date = nweekdate(n,Weekday,Year,Month) returns the date number for the specific occurrence of the weekday in the given Year and Month.

Any input argument can contain multiple values, but if so, all other input arguments must contain the same number of values or a single value that applies to all. For example, if Year is a 1-by-n vector of integers, then Month must be a 1-by-n vector of integers or a single integer. Date is then a 1-by-n vector of date numbers.

Use the function datestr to convert serial date numbers to formatted date character vectors.

example

Date = nweekdate(n,Weekday,Year,Month,Same,outputType) returns the date number for the specific occurrence of the weekday in the given Year and Month and also contains the optional arguments for weekday Same and outputType.

Examples

collapse all

Find the first Thursday in May 2001.

Date = nweekdate(1, 5, 2001, 5);
datestr(Date)
ans =

03-May-2001

Find the first Thursday in May 2001 returned as a datatime array.

Date = nweekdate(1, 5, 2001, 5,[],'datetime')
Date = 

  datetime

   03-May-2001

Find the first Thursday in a week that also contains a Wednesday in May 2001.

Date = nweekdate(2, 5, 2001, 5, 4);
datestr(Date)
ans =

10-May-2001

Find the third Monday in February for 2001, 2002, and 2003.

Year = [2001:2003];
Date = nweekdate(3, 2, Year, 2);
datestr(Date)
ans =

19-Feb-2001
18-Feb-2002
17-Feb-2003

Related Examples

Input Arguments

collapse all

Nth occurrence of the weekday in a month, specified as an integer or a vector of integers from 1 through 5.

If n is larger than the last occurrence of Weekday, the output Date = 0.

Data Types: single | double

Weekday whose date you seek, specified as an integer or a vector of integers from 1 through 7.

  • 1 — Sunday

  • 2 — Monday

  • 3 — Tuesday

  • 4 — Wednesday

  • 5 — Thursday

  • 6 — Friday

  • 7 — Saturday

Data Types: single | double

Year to determine occurrence of weekday, specified as a 4-digit integer or vector of 4-digit integers.

Data Types: single | double

Month to determine occurrence of weekday, specified as an integer or vector of integers with values 1 through 12.

Data Types: single | double

Weekday that must occur in the same week with Weekday, specified as an integer or a vector of integers from 0 through 7, where 0 = ignore (default) and 1 through 7 are as for Weekday.

Data Types: single | double

A character vector specified as either 'datenum' or 'datetime'. The output Date is in serial date format if 'datenum' is specified, or datetime format if 'datetime' is specified. By default the output Date is in serial date format.

Data Types: single | double

Output Arguments

collapse all

Date of specific occurrence of weekday in month, returned as a serial date number or date character vector.

The type of the output for Date depends on the input outputType. If this variable is 'datenum', Date is a serial date number. If outputType is 'datetime', then Date is a datetime array. By default, outputType is set to 'datenum'.

Introduced before R2006a


Was this topic helpful?