• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 929
  • Last Modified:

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,
0
Ritesh_Garg
Asked:
Ritesh_Garg
  • 2
1 Solution
 
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
 
Ritesh_GargAuthor Commented:
Holidays was handled in independent functions.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now