Getting a list of business days ignoring holidays regardless of timezone/country.
6 views (last 30 days)
Show older comments
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.
0 Comments
Answers (1)
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)
%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.
0 Comments
See Also
Categories
Find more on Calendar 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!