Main Content

fbusdate

First business date of month

Description

Date = fbusdate(Year,Month) returns the serial date number for the first 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, ifYear 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 datetimes or serial date numbers.

Use the function datetime to convert serial date numbers to formatted datetime arrays.

example

Date = fbusdate(___,Holiday,Weekend,outputType) returns the serial date number for the first 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.

example

Examples

collapse all

This example shows how to return serial date numbers for the first business date, given year and month.

Date = fbusdate(2001, 11)
Date = 
731156
datestr(Date)
ans = 
'01-Nov-2001'
Year = [2002 2003 2004];
Date = fbusdate(Year, 11) 
Date = 1×3

      731521      731888      732252

datestr(Date)
ans = 3x11 char array
    '01-Nov-2002'
    '03-Nov-2003'
    '01-Nov-2004'

This example shows how to return serial date numbers for the first business date, given year and month, and also indicate that Saturday is a business day by setting the Weekend argument. March 1, 2003, is a Saturday. Use fbusdate to check that this Saturday is actually the first business day of the month.

Weekend = [1 0 0 0 0 0 0];
Date = datestr(fbusdate(2003, 3, [], Weekend))
Date = 
'01-Mar-2003'

This example shows how to return a datetime array for Date using an outputType of 'datetime'.

Date = fbusdate(2001, 11,[],[],'datetime')
Date = datetime
   01-Nov-2001

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 vector using a datetime array, string array, date character vectors, or serial date numbers.

Note

The holidays function supplies the default vector.

All dates in Holiday must be the same format: either datetimes, strings, or date character vectors.

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, fbusdate 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 first 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 datetime to convert serial date numbers to formatted datetime arrays.

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

.

Version History

Introduced before R2006a

expand all