Main Content

lbusdate

Last business date of month

Description

Date = lbusdate(Year,Month) returns the serial date number for the last business date of the given year and month.

Year and Month can contain multiple values. If one contains multiple values, the other 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 serial date numbers.

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

Date = lbusdate(___,Holiday,Weekend,outputType) returns the serial date number for the last business date of the given year and month using optional input arguments. The optional argument Holiday specifies nontrading days.

If neither Holiday nor outputType are specified, Date is returned as a serial date number. If Holiday is specified, but not outputType, then the type of the holiday variable controls the type of date. If Holiday is a string or date character vector, then Date is returned as a serial date number.

Examples

collapse all

Determine the Date using an input argument for Year and Month.

Date = lbusdate(2001, 5)
Date = 731002
datestr(Date)
ans = 
'31-May-2001'

Determine the Date using the optional input argument for outputType.

Date = lbusdate(2001, 11,[],[],'datetime')
Date = datetime
   30-Nov-2001

Indicate that Saturday is a business day by appropriately setting the Weekend argument. May 31, 2003, is a Saturday. Use lbusdate to check that this Saturday is actually the last business day of the month.

Weekend = [1 0 0 0 0 0 0];
Date = lbusdate(2003, 5, [], Weekend,'datetime')
Date = datetime
   31-May-2003

Input Arguments

collapse all

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

Data Types: double

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

Data Types: double

Holidays and nontrading-day dates, specified as a vector using a datetime array, string array, or date character vectors.

All dates in Holiday must be the same format: either datetimes, strings, or date character vectors. The holidays function supplies the default vector.

If Holiday is a datetime array, then Date is returned as a datetime array. If outputType is specified, then its value determines the output type of Date. This overrides any influence of Holiday.

To support existing code, lbusdate also accepts serial date numbers as inputs, but they are not recommended.

Data Types: char | string | datetime

Weekend days, specified as a vector of length 7, containing 0 and 1, where 1 indicates weekend days and the first element of this vector corresponds to Sunday.

Data Types: 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, or match the format of Holiday, if specified.

Data Types: char

Output Arguments

collapse all

Date for the last business date of a given year and month, returned as a datetime or serial date number.

If neither Holiday nor outputType are specified, Date is returned as a serial date number. If Holiday is specified, but not outputType, then the type of the holiday variable controls the type of date:

  • If Holiday is a string or date character vector, then Date is returned as a serial date number. Use the function datestr to convert serial date numbers to formatted date character vectors.

  • If Holiday is a datetime array, then Date is returned as a datetime array.

.

Version History

Introduced before R2006a

expand all