Documentation

This is machine translation

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

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

lweekdate

Date of last occurrence of weekday in month

Syntax

  • LastDate = lweekdate(Weekday,Year,Month)
    example
  • LastDate = lweekdate(Weekday,Year,Month,NextDay,outputType)
    example

Description

example

LastDate = lweekdate(Weekday,Year,Month) returns the date number for the last occurrence of Weekday in the given year and month.

Any input can contain multiple values, but if so, all other inputs 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, thenMonth must be a 1-by-n vector of integers or a single integer. LastDate is then a 1-by-n vector of date numbers.

example

LastDate = lweekdate(Weekday,Year,Month,NextDay,outputType) returns the date of last occurrence of weekday in month using the optional arguments for NextDay and outputType.

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

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

Examples

collapse all

Determine the last Monday in June 2001.

LastDate = lweekdate(2, 2001, 6); datestr(LastDate)
ans =

25-Jun-2001

Determine the last Monday in a week that also contains a Friday in June 2001 returned as a datetime array.

LastDate = lweekdate(2, 2001, 6,[],'datetime')
LastDate = 

  datetime

   25-Jun-2001

Determine the last Monday in a week that also contains a Friday in June 2001:

LastDate = lweekdate(2, 2001, 6, 6); datestr(LastDate)
ans =

25-Jun-2001

Determine the last Monday in May for 2001, 2002, and 2003:

Year = [2001:2003];
LastDate = lweekdate(2, Year, 5);
datestr(LastDate)
ans =

28-May-2001
27-May-2002
26-May-2003

Related Examples

Input Arguments

collapse all

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 after Weekday in same week, specified as an integer or a vector of integers from 0 through 7, where 0 = ignore (default) and 1 through 7 are the same as for Weekday.

Data Types: single | double

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

Data Types: char

Output Arguments

collapse all

Date for last occurrence of Weekday in given year and month, returned as a serial date number or date character vector.

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

Introduced before R2006a

Was this topic helpful?