Main Content

datewrkdy

Date of future or past workday

Description

example

EndDate = datewrkdy(StartDate,NumberWorkDays,NumberHolidays) returns the datetime of the date a given number of workdays before or after the start date.

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 StartDate is an n-row datetime, then NumberWorkDays must be an N-by-1 vector of integers or a single integer. EndDate is then an N-by-1 vector of datetimes.

If StartDate is a string or date character vector, EndDate is returned as a serial date number. Use the function datestr to convert serial date numbers to formatted date character vectors.

If StartDate is a datetime array, then EndDate is returned as a datetime array.

Examples

collapse all

Determine the EndDate for a future workday using a date character vector for StartDate.

StartDate = '20-Dec-1994';
NumberWorkDays = 16;
NumberHolidays = 2;
 
EndDate = datewrkdy(StartDate, NumberWorkDays, NumberHolidays)
EndDate = 728671
datestr(EndDate)
ans = 
'12-Jan-1995'

Determine the EndDate for a future workday using a datetime for StartDate.

EndDate = datewrkdy(datetime(2000,12,12), 16, 2)
EndDate = datetime
   04-Jan-2001

Determine the EndDate for future workdays using a vector for NumberWorkDays.

NumberWorkDays = [16; 20; 44];
EndDate = datewrkdy(datetime(2000,12,12), NumberWorkDays, 2)
EndDate = 3x1 datetime
   04-Jan-2001
   10-Jan-2001
   13-Feb-2001

Input Arguments

collapse all

Start date, specified as an N-by-1 or 1-by-N vector using a datetime array, string array, or date character vectors.

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

Data Types: char | string | datetime

Number of work or business days in future (positive) or past (negative) that includes the starting date, specified as an N-by-1 or 1-by-N vector containing positive or negative integers.

NumberHolidays and NumberWorkDays must have the same sign.

Data Types: double

Number of holidays within NumberWorkDays, specified as positive or negative integers using an N-by-1 or 1-by-N containing values for the number of days movement in terms of holidays into the future (if positive) or past (if negative).

NumberHolidays and NumberWorkDays must have the same sign.

Data Types: double

Output Arguments

collapse all

Date of future or past workday, returned as an N-by-1 or 1-by-N vector for the future or past date.

Version History

Introduced before R2006a

expand all