Documentation

lbusdate

Last business date of month

Syntax

Date = lbusdate(Year, Month, Holiday, Weekend, outputType)

Arguments

Year

Enter as four-digit integer.

Month

Enter as integer from 1 through 12.

Holiday

(Optional) Vector of holidays and nontrading-day dates. All dates in Holiday must be the same format: either serial date numbers or date character vectors. (Using date numbers improves performance.) The holidays function supplies the default vector.

Weekend

(Optional) Vector of length 7, containing 0 and 1, the value 1 indicating weekend days. The first element of this vector corresponds to Sunday. Thus, when Saturday and Sunday form the weekend (default), then Weekend = [1 0 0 0 0 0 1].

outputType

(Optional) A character vector specified as either 'datenum' or 'datetime'. The output Date will be in serial date format if 'datenum' is specified or datetime format if 'datetime' is specified. By default the output will be in serial date format, or match the format of Holiday, if specified.

Description

Date = lbusdate(Year, Month, Holiday, Weekend, outputType) returns the serial date number for the last business date of the given year and month, if neither Holiday or outputType are specified.

Holiday specifies nontrading days. If Holiday is specified, but not outputType, then the type of the holiday variable controls the type of date. If Holiday is a serial date number or date character vector, then Date is returned as a serial date number. However, 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. If outputType is 'datenum', then Date is returned as a serial date number. If outputType is'datetime', then Date is returned as a datetime array. Any other values will result in an error.

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 date numbers.

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

Examples

Example 1.

Date = lbusdate(2001, 5)
Date =

      731002
datestr(Date)
ans =

31-May-2001

Example 2.

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

   30-Nov-2001

Example 3. You can indicate that Saturday is a business day by appropriately setting the Weekend argument.

Weekend = [1 0 0 0 0 0 0];

May 31, 2003, is a Saturday. Use lbusdate to check that this Saturday is actually the last business day of the month.

Date = datestr(lbusdate(2003, 5, [], Weekend))
Date =

31-May-2003

Related Examples

Introduced before R2006a

Was this topic helpful?