We can use fbusdate
to get the first business day of a month:
Date = fbusdate(Year, Month);
However, how do we get the first business day of a week?
As an example, during the week that I'm posting this, Monday 09/07/2017 was a holiday in the US:
isbusday(736942) % = 0
How do I determine that the first business day for this week would be the next day 736943
?
DayNumber = weekday( D ) returns a number representing the day of the week for each element in D . [ DayNumber , DayName ] = weekday( D ) additionally returns abbreviated English names for the day of the week, in DayName .
Busday = isbusday( Date ) returns logical true ( 1 ) if Date is a business day and logical false ( 0 ) otherwise. Busday = isbusday(___, Holiday , Weekend ) , using optional input arguments, returns logical true ( 1 ) if Date is a business day, and logical false ( 0 ) otherwise.
Date = today returns the current date as a serial date number. Date = today( outputType ) returns the current date using an optional outputType . The type of output is determined by an optional outputType variable input.
I'm not aware of a builtin function that returns the first working day of a week, but you can obtain it by requesting the next working day after Sunday:
busdate(736941); % 736941 = Sunday 09/03/2017
Your desired fbusdateweek
function can be done in one line using just the function weekday
to get the first Sunday of the week then busdate
to get the next business day after that:
dn = 736942; % Date number for any day in a week
Date = busdate(dn-weekday(dn)+1);
Note: busdate
uses the function holidays
by default to get all holidays and special nontrading days for the New York Stock Exchange. If necessary, you can define an alternate set of holidays for busdate
to use as follows:
holidayArray = ...; % Some set of date numbers, vectors, or datetimes
Date = busdate(dn-weekday(dn)+1, 1, holidayArray);
This way you can define a set of localized holidays.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With