Bank Holiday Check

I am trying to populate a field  called RF_BANK_DATE which is derived element and the business what this field to be populated based on RF_Post_date..(please review the below)
However there is an issue with the below logic if the RF_Post_Date happens to on a Friday then we are going to set RF_Bank_Date to either Saturday/Sunday or if it posted on a working day then if the following day is a bank holiday then the RF_BANK_DATE is not valid because there will not any exchange of funds on a sat or Sunday or on a holiday.

So I have to modify the logic so that I can exclude Bank Holidays ? How do I do that ? Please help me ASAP
DBMS NAME - Sybase Adaptive Server Anywhere
DBMS Version- 12.70

 Update itsrf
     SET RF_Bank_dt =
         CASE
             WHEN Home_Host_Code = 'Home' AND itsrf.RF_Post_Date = today()-1 THEN itsrf.RF_Post_Date + 2
             WHEN Home_Host_Code = 'Home' AND itsrf.RF_Post_Date = today() THEN itsrf.RF_Post_Date + 1
             WHEN Home_Host_Code = 'Host' AND itsrf.ITS_Central_Financial_Agency_Disp_Date = today()-1 THEN
                  itsrf.ITS_Central_Financial_Agency_Disp_Date + 2
             WHEN Home_Host_Code = 'Host' AND itsrf.ITS_Central_Financial_Agency_Disp_Date = today() THEN
                  itsrf.ITS_Central_Financial_Agency_Disp_Date + 1
             ELSE '1800-01-01'
              END


Thank you,
LVL 6
Ritesh_GargAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

wilcoxonCommented:
This code should work to handle weekends correctly.  However, there is no easy way to handle weekday bank holidays as there is no uniformity to them.
set @@datefirst 2 -- do this so sat = 6 and sun = 7
declare @post_dt datetime, @dow tinyint
select @post_dt =
         CASE
             WHEN Home_Host_Code = 'Home' AND itsrf.RF_Post_Date = today()-1 THEN itsrf.RF_Post_Date + 2
             WHEN Home_Host_Code = 'Home' AND itsrf.RF_Post_Date = today() THEN itsrf.RF_Post_Date + 1
             WHEN Home_Host_Code = 'Host' AND itsrf.ITS_Central_Financial_Agency_Disp_Date = today()-1 THEN
                  itsrf.ITS_Central_Financial_Agency_Disp_Date + 2
             WHEN Home_Host_Code = 'Host' AND itsrf.ITS_Central_Financial_Agency_Disp_Date = today() THEN
                  itsrf.ITS_Central_Financial_Agency_Disp_Date + 1
             ELSE '1800-01-01'
         END 
from itsrf

-- if day-of-week is weekend (6-7), invert (-6 or -7) and add 8 to get +1 or +2
select @dow = datepart('weekday', @post_dt)
if (@dow > 5)
    select @post_dt = dateadd(day, @dow * -1 + 8, @post_dt)

Update itsrf set RF_Bank_dt = @post_dt

Open in new window

0
Joe WoodhousePrincipal ConsultantCommented:
I've only seen bank holidays handled ad-hoc for each state or province. You can have a table just of bank holidays, or a table of all days in the year, with a flag for which days are business/bank days and which are not. The SQL expressions become pretty simple then.
0
wilcoxonCommented:
If you are handling bank holidays for a specific location, it becomes simple(ish).  The general case is very, very complex.  You have national holidays.  You have state/regional holidays (and sometimes "anti" holidays where they don't follow national holidays).  You can also have city/local holidays (which again sometimes may include not following higher "level" holidays).  In some places, it can be impossible to predict when the holiday will be (several of the middle eastern countries have holidays that are at the whim of the current ruler or religious official).
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ritesh_GargAuthor Commented:
Holidays was handled in independent functions.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Sybase Database

From novice to tech pro — start learning today.