Determine if a day is a bank holiday (from a matrix)

5 ビュー (過去 30 日間)
Andreas Georgakakos
Andreas Georgakakos 2018 年 2 月 13 日
コメント済み: Fangjun Jiang 2018 年 2 月 14 日
Hello there,
I have an issue, trying to check if a datetime vector is a bank holiday. The datetimes of the bankholidays are included in a seperate vector, called BankHolidays.
BankHolidays =
8×1 datetime array
02-01-2017
14-04-2017
17-04-2017
01-05-2017
29-05-2017
28-08-2017
25-12-2017
26-12-2017
How can I check if a specific datetime vector (e.g. date1) is a Bankholiday by comparing its datetime with the datetime of BankHolidays?
I have tried this:
any(date1 == BankHolidays) == false
But the results are not good. I also tried to calculate the respective datenum of the two vectors but I am getting different results for the same days, despite the fact that the date format is the same (dd/mm/yyyy).
I would appreciate your insight into this.
PS. I would like to avoid isbusday.
Thank you in advance,
Andreas

回答 (1 件)

Fangjun Jiang
Fangjun Jiang 2018 年 2 月 13 日
編集済み: Fangjun Jiang 2018 年 2 月 13 日
t1 = datetime(2014,1:5,1)
t2 = datetime(2014,1,1)
ismember(t2,t1)
  7 件のコメント
Andreas Georgakakos
Andreas Georgakakos 2018 年 2 月 14 日
Hi Steven,
My datetimes are hourly for a whole year (8760 values), for example:
01/01/2017 00:00
01/01/2017 01:00 ....
31/12/2017 23:00
In order to compare dates either by checking equality or by converting to datenum (?), is it better to remove hours and minutes or converting all the hours to 00:00 ?
Thanks.
Andreas
Fangjun Jiang
Fangjun Jiang 2018 年 2 月 14 日
t=datetime(2017,1,1):hours(1):datetime(2017,12,31,23,00,00)
t2=dateshift(t,'start','day')
ismember(t2,BankHolidays)

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCalendar についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by