Why do I get dates beyond the end date while using the BUSDAYS function with the 'weekly' option?

1 view (last 30 days)
The following code illustrates the problem:
v=datestr(busdays('5/22/00','5/20/02','weekly'));
v(end,:)
The above code gives the following output for the last date 'v(end,:)' generated by the BUSDAYS function:
ans =
24-May-2002
It is evident that the last date in the output of the BUSDAYS function goes beyond the end date.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
This change has been incorporated into the documentation in Release 14 Service Pack 3 (R14SP3). For previous releases, read below for any additional information:
This is not a bug . It was coded to do exactly what you have indicated.
If you choose weekly, the code considers Fridays as the end of the week and generates "full" weeks between the start and end date supplied. So if you happen to provide a date that is in the middle of the week, the code pads more dates to make it a full week.
If you do not want those last dates, you can remove the last date in the ouput of the BUSDAYS function, as follows:
v=datestr(busdays('5/22/00','5/20/02','weekly'));
%The last date in 'v' which is beyond the end date 05/20/02
v(end,:)
%This will remove the last date
vnew=v(1:end-1,:);
For more information, refer to the help documentation of the BUSDAYS function, by issuing the following command:
help busdays

More Answers (0)

Categories

Find more on Financial Toolbox in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!