Getting a list of business days ignoring holidays regardless of timezone/country.

3 views (last 30 days)
Hello,
I'd like to make an array of dates containing business days regardless of the holidays (if there's any within that range).
The list I can make it like this:
start='12/11/2017';
finish='12/15/2017';
formatOut = 'mm/dd/yy';
date_vector=string(datestr(busdays(start,finish),formatOut));
Reading the docs, I looked at 'holvec' input for the busdays function. I'm not sure how to configure it in order to get any business day regarding the timezone (I'll be working with data from different places and a holiday in one hardly will be a holiday in another).
Should I configure 'holvec' in the busdays function? Or with the current settings I have, I don't have to care about holidays at all?
Thanks in advance.

Answers (1)

Ben
Ben on 7 Nov 2023
If you are working with dates it is best to use datetime, and I don't like that date format, so I will answer using datetime. It should be possible to also use datestr if you really want to.
Looking at the busdays docs the holiday list used by default is for the US, but can be replaced with our own list of holiday dates.
As you want 0 holidays, you can make the list of holidays provided to busdays (and other functions like isbusday) that only contains data outside the range of your data. The holidays list you manually provide replaces the US-holidays data.
startDate = datetime(2017,12,11);
endDate = datetime(2017,12,15);
fakeHoliday = datetime(1,1,1); %Creates a datetime entry for 01-Jan-0001
date_vector = busdays(startDate,endDate,1,fakeHoliday)
date_vector = 5×1 datetime array
11-Dec-2017 12-Dec-2017 13-Dec-2017 14-Dec-2017 15-Dec-2017
%If it must be strings
formatOut = 'mm/dd/yy';
date_strs = string(datestr(date_vector,formatOut));
Though your provided date range doesn't include any holidays, so you need the actual range to see if it works.

Community Treasure Hunt

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

Start Hunting!