Main Content

busdate

Next or previous business day

Description

example

Busday = busdate(Date) returns the scalar, vector, or matrix of the next or previous business days, depending on the definition for Holiday.

example

Busday = busdate(___,DirFlag,Holiday,Weekend) returns the scalar, vector, or matrix of the next or previous business days, depending on the optional input arguments, including Holiday.

If both Date and Holiday are either strings or date character vectors, Busday is returned as a serial date number. Use the function datestr to convert serial date numbers to formatted date character vectors.

However, if either Date or Holiday are datetime arrays, Busday is returned as a datetime array.

Examples

collapse all

Determine the next business day when Date is a character vector.

 Busday = busdate('3-Jul-2001', 1)
Busday = 731037
datestr(Busday)
ans = 
'05-Jul-2001'

Indicate that Saturday is a business day by appropriately setting the Weekend argument. July 4, 2003 falls on a Friday. Use busdate to verify that Saturday, July 5, is actually a business day.

Weekend = [1 0 0 0 0 0 0];
Date = datestr(busdate('3-Jul-2003', 1, [], Weekend))
Date = 
'05-Jul-2003'

If either Date or Holiday are datetime arrays, Busday is returned as a datetime array.

Busday = busdate(datetime('3-Jul-2001','Locale','en_US'), 1)
Busday = datetime
   05-Jul-2001

Also, you can bypass a holiday.

busdate(datetime(2022,11,23),1,NaT)
ans = datetime
   24-Nov-2022

Input Arguments

collapse all

Reference business date, specified as a scalar, vector, or matrix using a datetime array, string array, or date character vectors.

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

Data Types: char | string | datetime

Business day convention, specified date character vector or cell array of date character vectors with values of follow, modifiedfollow, previous, or modifiedprevious.

Also, DirFlag can be a scalar, vector, or matrix of search directions, where Next is DIREC = 1 (default) or Previous is DIREC = -1.

Data Types: double | char | datetime

Holidays and nontrading-day dates, specified as 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.

Note

To bypass holidays and nontrading dates, use NaT. For example, busdate(datetime(2022,11,23),1,NaT).

To support existing code, busdate 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

Output Arguments

collapse all

Next or previous business day, returned as a scalar, vector, or matrix depending on the definition for Holiday.

Version History

Introduced before R2006a

expand all