Business days table

Hi All,
I want to create a business day table that exclude weekends and company holidays. Here is an example what I am trying to achieve:
Date BusDays Holidy MTDBusDy
1/1/09,0,Y, 0
1/2/09,0,Y,0
1/3/09,0,NULL,0
1/4/09,0,NULL,0
1/5/09,1,NULL,1
1/6/09,1,NULL,2
1/7/09,1,NULL,3
1/16/09,1,NULL,10
1/17/09,1,NULL,10
1/18/09,1,NULL,10
1/19/09,0,Y,10
1/20/09,1,NULL,11
1/31/09,1,NULL,19
12/31/09,1...
I figured out how to get the data for the first 3 columns but need help on 'MTD BusDy' - stands for Month to Date Business Days - column.
Any help could be greatly appreciate it.
Regards,
MChu

The business days in this example don't line up with yours, but the formula is the same:
SQL> select cal_date
  2        ,bus_day
  3        ,sum(bus_day) over (partition by to_char(cal_date,'YYYYMM') order by cal_date) mtd_bus
  4  from   bus_calendar;
CAL_DATE                          BUS_DAY              MTD_BUS
01-JAN-2009 00:00:00                    1                    1
02-JAN-2009 00:00:00                    1                    2
03-JAN-2009 00:00:00                    0                    2
04-JAN-2009 00:00:00                    0                    2
05-JAN-2009 00:00:00                    1                    3
06-JAN-2009 00:00:00                    1                    4
07-JAN-2009 00:00:00                    1                    5
08-JAN-2009 00:00:00                    1                    6
09-JAN-2009 00:00:00                    1                    7
10-JAN-2009 00:00:00                    0                    7
11-JAN-2009 00:00:00                    0                    7
12-JAN-2009 00:00:00                    1                    8
13-JAN-2009 00:00:00                    1                    9
14-JAN-2009 00:00:00                    1                   10
15-JAN-2009 00:00:00                    1                   11
16-JAN-2009 00:00:00                    1                   12
17-JAN-2009 00:00:00                    0                   12
18-JAN-2009 00:00:00                    0                   12
19-JAN-2009 00:00:00                    1                   13
20-JAN-2009 00:00:00                    1                   14
21-JAN-2009 00:00:00                    1                   15
22-JAN-2009 00:00:00                    1                   16
23-JAN-2009 00:00:00                    1                   17
24-JAN-2009 00:00:00                    0                   17
25-JAN-2009 00:00:00                    0                   17
26-JAN-2009 00:00:00                    1                   18
27-JAN-2009 00:00:00                    1                   19
28-JAN-2009 00:00:00                    1                   20
29-JAN-2009 00:00:00                    1                   21
30-JAN-2009 00:00:00                    1                   22
31-JAN-2009 00:00:00                    0                   22
31 rows selected.

Similar Messages

  • Add number of business days to date field

    Hello, I noticed that there is not much discussion in the forum surrounding u201Cbusiness daysu201D so I hope this post/discussion/solution contributes to the content of this forum.
    I am using the following 3 formulas to try to Add number of business days (based upon a table field) to a specified date:
    1. Variable name = SetVar
    //Set Variable for Add Business Days:
    DateVar Array Holidays;
    DateVar Target:= CDate({TMS_MOVEMENT_EVT.EVT_DATE}); // Put your field name in here
    NumberVar Add:=  {DTCI_DOD_TRANS.TRANS}; // put the number of days here to add (a positive number)
    NumberVar Added := (0);
    2. Variable name = AddBizDays
    //Adding Business Days:
    EvaluateAfter({@SetVar});
    WHILE Added < Add
    Do (target := target +1;
        if dayofweek (target) in 2 to 6 and not (target in holidays)
            then Added:=Added+1
            else Added:=Added);
    Target
    3. Variable name = HOLIDAYS
    //Holiday Array Formula for the report Header:
    BeforeReadingRecords;
    DateVar Array Holidays := [
    Date (2003,12,25),   // you can put in as many lines for holidays as you want. 
    Date (2003,12,31)
    0
    I am successfully getting my data needed to make the necessary calculations and variable assignmentsu2026 I believe that my ISSUE is that I am not sure where to place these formulas into my report so they assign the variables and execute properly when previewing my report. I am curious if that is my issue, and if so, can someone provide me direction on where to put each of these formulas in my report.
    Currently, when I try to preview the report, I get the following Crystal Reports Error:  -u201CA number, currency amount, Boolean, date, time, date-time, or string is expected here.u201D
    Then Crystal automatically opens the AddBizDays formula and highlights the word added, see below RE: u201CWHILE Addedu201D
    For reference, my report has 3 groups, and I am displaying all of my output information (and locating my formulas) in the group footer #3 report section. I have moved them around to other report sections/groups/placements, but to no success.
    Thanks so much.
    Best, Matt

    I worked this out... FYI - for the benefit of all forum users:
    ADDING BUSINESS DAYS TO A CERTAIN DATE (excluding weekends and holidays)
    1. Variable name = AddBizDays
    //Adding Business Days:
    WhileReadingRecords;
    DateVar Array Holidays;
    DateVar Target:= CDate(); // Put your field name in here
    NumberVar Add:=  ; // put the number of days here to add (a positive number)
    NumberVar Added := (0);
    WHILE Added < Add
    Do (target := target +1;
        if dayofweek (target) in 2 to 6 and not (target in holidays)
            then Added:=Added+1
            else Added:=Added);
    Target
    2. Variable name = HOLIDAYS
    //Holiday Array Formula for the report Header:
    BeforeReadingRecords;
    DateVar Array Holidays := [
    Date (2003,12,25), // you can put in as many lines for holidays as you want.
    Date (2003,12,31)
    0
    ...too bad i don't get forum points for sharing this solution.
    Special thanks to KenHamady.com -- for sharing this solution.
    Sincerely,
    Matt

  • How can i find the 1st business day of the week ?

    Hi,
    How can i find the 1st business day of the week excluding saturaday,sunday and holidays? i have holiday table which contains the columns name HolidayDate and HolidayDescription.
    Ex:
    10-1-2011 is monday(i.e) 1st business day.check If it is in holiday table,then return the result as 11-1-2011 else return the result as 11-1-2011(which is the first business day of this week).
    Can anyone tell me the Query to solve it?

    Does this help:
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (SELECT TRUNC(SYSDATE,'IW') holiday FROM dual
      2  UNION SELECT TRUNC(SYSDATE + 7,'IW') from dual)
      3  SELECT MIN(Dat),wk FROM
      4  (SELECT TO_CHAR(dat,'IW') wk,dat FROM
      5  (SELECT dat + lvl dat FROM
      6  (SELECT TRUNC(SYSDATE,'RRRR') dat, level - 1 lvl
      7  FROM dual
      8  CONNECT BY level <= TO_DATE('31-DEC'||TO_CHAR(SYSDATE,'RRRR')) - TRUNC(SYSDATE,'RRRR'))
      9  ) x
    10  WHERE x.dat NOT IN (select holiday from t))
    11  WHERE TO_CHAR(Dat,'DY') <> 'SAT'
    12  AND TO_CHAR(dat,'DY') <> 'SUN'
    13* group by wk
    SQL> /
    MIN(DAT)  WK
    04-JAN-11 01  -- since 03-JAN-2011 is in holiday list, 04 is taken as first business day of first week
    11-JAN-11 02  -- similar to week 1
    17-JAN-11 03
    24-JAN-11 04
    31-JAN-11 05
    07-FEB-11 06
    14-FEB-11 07
    21-FEB-11 08
    28-FEB-11 09
    07-MAR-11 10
    14-MAR-11 11
    21-MAR-11 12
    28-MAR-11 13
    04-APR-11 14
    11-APR-11 15
    18-APR-11 16
    25-APR-11 17
    02-MAY-11 18
    09-MAY-11 19
    16-MAY-11 20
    23-MAY-11 21
    30-MAY-11 22
    06-JUN-11 23
    13-JUN-11 24
    20-JUN-11 25
    27-JUN-11 26
    04-JUL-11 27
    11-JUL-11 28
    18-JUL-11 29
    25-JUL-11 30
    01-AUG-11 31
    08-AUG-11 32
    15-AUG-11 33
    22-AUG-11 34
    29-AUG-11 35
    05-SEP-11 36
    12-SEP-11 37
    19-SEP-11 38
    26-SEP-11 39
    03-OCT-11 40
    10-OCT-11 41
    17-OCT-11 42
    24-OCT-11 43
    31-OCT-11 44
    07-NOV-11 45
    14-NOV-11 46
    21-NOV-11 47
    28-NOV-11 48
    05-DEC-11 49
    12-DEC-11 50
    19-DEC-11 51
    26-DEC-11 52
    52 rows selected.
    SQL>

  • Get Next business day conditionally

    Hi All,
    I have a calendar table with all federal holidays, saturdays and sundays flagged to 1.
    I need help in finding the next business day from givendate and that too Conditionallly.. means
    Lets say today's date is 01/02/2014(wednesday) and I want to know the next businessday after 10 days which would be 01/16/2014(thursday). Exclude saturdays and sundays in between.
    I started like this..but gives me wrong date..
    Also, when 10th day is saturday or sunday or any holiday it should give next business day.
    so i need help in tweaking my query.
    select NextBusinessDay = min(a.Date)+10
    from  [dbo].[Calendar] a
    where
     a.Date > GETDATE() 
     and a.day_Name not in ('Saturday','Sunday')
     and a.IsHoliday <> 1
    Thanks,
    RH
    sql

    Try this out:
    DECLARE @calendar TABLE (date DATE, holiday BIT, weekend BIT)
    DECLARE @i INT = 0
    SET NOCOUNT ON
    WHILE @i < 50
    BEGIN
    INSERT INTO @calendar (date, holiday, weekend)
    VALUES (DATEADD(DAY,@i,'2014-01-01'),0,CASE WHEN DATEPART(WEEKDAY,DATEADD(DAY,@i,'2014-01-01')) IN (1,7) THEN 1 ELSE 0 END)
    SET @i = @i + 1
    END
    UPDATE @calendar SET holiday = 1 WHERE date = '2014-01-20'
    SET NOCOUNT OFF
    SELECT max(date)
    FROM (
    SELECT TOP 10 *
    FROM @calendar
    WHERE date > '2014-01-02'
    AND holiday <> 1
    AND weekend <> 1
    ) a
    Obviously I've simulated your calendar, and forced a date into it.

  • Business days in month

    Hello,
    I need to create a new report with some external data, from a formula or table.
    This report is just a Total Amount value multiplied by the current business day in the total business days in the current month. This is just to preview the total amount expected in the end of the month. For example:
    The current sales ammount is 100, and today is the business day 15. The month have 22 business days so: 100 * (22/15) = 146,66. This is just an a approximate value in the end of the month.
    The problem is: How can I get in a column the value of the business day of today?, and, how can I get the total business days in the current month?.
    I've tried to get those values froma a sql function (actually this is working) but i can't use this inside Oracle BI.
    Also, I've tried to make a table with all the values of this columns. Date - Business day in month - Total business days in month. Then import at the repository with date dimension relationship, but in BI it gets the date of the last Sale (maybe the last sale was 2 days ago, and the relationship with my table was with Date, not today.
    It's hard to explain, but essentialy I need to get just to values: Today Business Day and Total business day. I can generate this values with any other tecnology (Oracle, any language, table...) but unable to import or use it inside oracle BI.
    Thanks.

    Since you raised this under a E-business suite subforum, I assume you have EBS.
    Normally in Oracle EBS, each organization is associated with a calendar and the calendar specifies which day is a working day and which is not.
    That data is stored in bom_calendar_dates.
    Sandeep Gandhi

  • Fucntion to Calculate business days (exclude weekends & holidays) between two days

    Hello,
    I need to be able to calculate business days between two dates excluding weekends and holidays. I do have a date dimension and also flags which denote weekday, holiday. Would really appreciate help in building a udf for the business days calculation.
    Thanks,

    Hi, Please take a look and tweak accordingly. Best of luck.
    --Assuming data dimension table something like the following
    --tblDateDim (DT date primary key,
    flagHoliday bit,
    flagWeekday bit
    CREATE FUNCTION fnBusinessDays (
    @StartDate DATE,
    @EndDate DATE
    RETURNS INT
    AS
    BEGIN
    DECLARE @Days INT ;
    SELECT @Days = count(*)
    FROM tblDateDim --// date dimension
    WHERE
    ( DT BETWEEN @StartDate AND @EndDate) --// dt is date column in the table.
    AND --// also flags which denote weekday, holiday
    flagHoliday = 0 --// flagHoliday= 1--Holiday;= 0 --workingday/businessday
    AND
    flagWeekday = 1 --// FlagWeekday = 1--businessday ; =0 --weekend (Saturday and Sunday)
    RETURN (@Days)
    END
    GO

  • Number of business days (excluding holidays) ?

    Hi All,
    What is the SQL query to find number of business days (excluding holidays) between 2 given dates ?
    List of Holidays will be maintained as a separate table.
    I need a SQL query rather than a stored procedure or function.
    I am using oracle 9i.
    Thanks in advance.

    Does this thread help?
    Need to find number of business days - query pls

  • Previous business day in sql query

    Hi,
    Is there a way to calculate the previous business day on teh sql query without using a function call.
    Typically in the query where clause as seen below:
    eg)
    select * from sales where sale_date ='+previous_buss_day+'
    If so please let me know....Thnx in advanc.

    that depends if your organization has a defined set of business days that will includes non-working days (holidays, etc.). if there is you need to have a lookup table that has a listing of all available normal business day and non-working days. then match it up with your transaction table. otherwise you can use the current system date less 1 days.
    e.g.
    select * from sales where sale_date = trunc(sysdate-1)

  • Calculating Business Days(Start_dt - End_dt)

    Hi Friends,
    Could anyone of you help me to find out the business days(Excluding Saturdays and Sundays) between two dates.
    The difference should be calculated of both the Start_dt and End_dt values truncated. The result should be calculated and stored according to business days, it means weekend days are to be ignored.
    create table sample (id number,start_dt date,end_dt date). The table values are as follows;
    ID ; start_dt ; End_dt
    1 ; 08-02-2012 ; 15-02-2012
    2 ; 30-12-2011 ; 15-02-2012
    My output should be;
    ID ; start_dt ; End_dt ; Expected Business Days (Excluding Weekends)
    1 ; 08-02-2012 ; 15-02-2012 ; 4
    2 ; 30-12-2011 ; 15-02-2012 ; 33
    Please note that, the Start Date and End Date can be any date from any year. Please help me on this.
    Regards,
    Williams.
    Edited by: Williams on Feb 8, 2012 6:28 PM
    Edited by: Williams on Feb 8, 2012 6:29 PM

    Here's my first cut at it.
    SQL> WITH sample AS
      2  (
      3     SELECT 1 AS id, TO_DATE('08-02-2012','DD-MM-YYYY') AS start_dt, TO_DATE('15-02-2012','DD-MM-YYYY') AS end_dt FROM DUAL UNION ALL
      4     SELECT 2 AS id, TO_DATE('30-12-2011','DD-MM-YYYY') AS start_dt, TO_DATE('15-02-2012','DD-MM-YYYY') AS end_dt FROM DUAL
      5  )
      6  /* END SAMPLE DATA */
      7  SELECT id
      8       , start_dt
      9       , end_dt
    10       , COUNT(*)
    11  FROM   sample
    12  JOIN   ( /* Exclude Weekends */
    13           SELECT dt
    14           FROM  ( /* Generate a range that includes all days */
    15                   SELECT min_start_dt + (LEVEL - 1) AS dt
    16                        , TO_CHAR
    17                          ( min_start_dt + (LEVEL - 1)
    18                          , 'fmDAY'
    19                          , 'NLS_DATE_LANGUAGE=AMERICAN'
    20                          ) AS dy
    21                   FROM   ( SELECT MIN(start_dt) AS min_start_dt
    22                                 , MAX(end_dt)   AS max_end_dt
    23                            FROM   sample
    24                          )
    25                   CONNECT BY LEVEL <= max_end_dt - min_start_dt + 1
    26                 )
    27           WHERE dy NOT IN ('SATURDAY','SUNDAY')
    28         ) dys ON dys.dt BETWEEN start_dt AND end_dt
    29  GROUP BY id
    30         , start_dt
    31         , end_dt
    32  /
            ID START_DT            END_DT                COUNT(*)
             2 12/30/2011 00:00:00 02/15/2012 00:00:00         34
             1 02/08/2012 00:00:00 02/15/2012 00:00:00          6
    2 rows selected.I got different results then you though. Can you say why your counts are what they are?

  • Working/Business Days with TimeStampDiff

    Hi,
    Background: I have an order table with a set of possible statuses. There also exists an audit trail that has a timestamp for when a certain status is set.
    Customer wants to measure between two different statuses - which is no problem with a timestampdiff between the two. However, there is also a need to subtract any day classified as a non-business day that falls between the two dates. What i've created is a table that contains the dates that are non-business days. In SQL, i would do this by doing the timestampdiff, then subtracting the count of days that falls between the two dates in the timestampdiff.
    The problem comes when i try to express this in the business model... I can of course do the timestampdiff, but i cannot seem to find a way to do the count of the days in the exception table. Anyone have an idea of how to solve this?

    The easiest way that i can think of is to have a database function created within the database which would accept the 2 dates as parameters and would return the count. Use EVALUATE to call the database function. Use my blog entry here http://oraclebizint.wordpress.com/2007/09/10/oracle-bi-ee-10133-support-for-native-database-functions-and-aggregates/ which would give you a basic idea of calling the database functions.
    Thanks,
    Venkat
    http://oraclebizint.wordpress.com

  • Subtracting/adding Business days

    Hi everyone !
    I have a calendar question: I have a date, number of days (either business or calendar) and Before/After indicator.
    I need to calculate the future/past date depending on business/calendar nn days.
    Ideally, I will also read Holidays table to fix the result with Holidays.
    Any suggestions ?
    CF allows me to know a weekday, add/subtract units from dates, compare dates, but nothing in the direction I mentioned...
    Any suggestions will be greatly appreciated !
    Gary.

    Make it very easy on yourself:  set up a database table with date as the primary-key, then fill it with 200 years' worth of dates.  ("When you run out, dig me up and I'll fix it then ...")  You can put any sort of information you want to in there, such as (for example...) a "business-day number" that's used only to calculate these differences.  It can literally be anything-and-everything you need to know about dates at your place of business.
    When you do this, not only are "complicated calculations" eliminated at-a-stroke, but you can very easily change anything at will.  You're simply using an inner-join and ... voila ... the answer is there.
    Although setting up a script (in whatever language) to populate the table is a bit tedious, you only need to do it once.  To me, it beats every other approach hands-down.

  • 30 Business Days Back

    Hi All,
    I need to find the calendar date 30 business days back from SYSDATE:
    Formula: Calendar Date = SYSDATE - "30 business days"
    I have a table contains:
    cal_dt,bus_day,holiday
    7/1/10,1,NULL
    7/2/10,1,NULL
    7/3/10,0,NULL
    7/4/10,0,NULL
    7/5/10,0,'Y'
    7/6/10,1,NULL
    For the life of me, I can't figure it out how to write the SQL? Please help.
    Using Oracle 10g.
    Thanks,
    Mary

    The first query gives you: Today's date - 30 'BUSINESS' days
    select cal_dt
    from
    select cal_dt, bus_day, holiday,
    row_number() over (order by cal_dt desc) rn
    from calendar
    where cal_dt <= TRUNC(SYSDATE)
    and bus_day = 1
    and holiday is NULL
    where rn = 31;
    The second query gives you: Last 'BUSINESS' day preceding (Today's date - 30 'CALENDER' days)
    Select cal_dt
    from (
    select cal_dt, bus_day, holiday,
    row_number() over (order by cal_dt desc) rn
    from calendar
    where cal_dt <= TRUNC(SYSDATE-30)
    and bus_day = 1
    and holiday is NULL
    where rn = 1;
    Or, you may try a simple alternative to my first query:
    select cal_dt
    from
    select cal_dt, ROWNUM rn
    from
    select cal_dt, bus_day, holiday
    from calendar
    where cal_dt <= TRUNC(SYSDATE)
    and bus_day = 1
    and holiday is NULL
    order by cal_dt
    where rn = 31;
    You may try to run these queries step by step to check what is happening and what suits to your needs.

  • Recursive CTE to get first business day excluding public holidays

    I wanted to write a recursive CTE to calculate the first business day excluding the public holidays for a given year. I have a table with the public holiday for that same year

    I like the functions I built to get this done:
    create function NthDayOfMonth (@year int, @month smallint, @weekday varchar(15), @nth smallint)
    returns datetime
    as
    begin
    declare @the_date datetime, @c_date datetime, @cth smallint
    set @cth = 0
    set @c_date = convert(varchar,@year)+'-'+convert(varchar,@month)+'-01'
    while month(@c_date) = @month
    begin
    if datename(weekday,@c_date) = @weekday set @cth = @cth + 1
    if @cth = @nth and datename(weekday,@c_date) = @weekday set @the_date = @c_date
    set @c_date = dateadd(day,1,@c_date)
    end
    return @the_date
    end
    GO
    create function Holidays(@year int)
    returns @table table
    date date,
    type varchar(10),
    name varchar(25)
    as
    begin
    insert into @table
    select convert(datetime,convert(varchar,@year)+'-01-01') as date,'Holiday' as type ,'New Years Day' as name UNION ALL
    select dbo.NthDayOfMonth(@year,2, 'Monday',3),'Holiday','Family Day' UNION ALL
    select dateadd(d,0-case when datepart(weekday,convert(varchar,@year)+'-05-25') in (1,2) then 5+datepart(weekday,convert(varchar,@year)+'-05-25') else datepart(weekday,convert(varchar,@year)+'-05-25')-1 end, convert(varchar,@year)+'-05-25') ,'Holiday','Victoria Day' UNION ALL
    select convert(varchar,@year)+'-07-01' ,'Holiday','Canada Day' UNION ALL
    select dbo.NthDayOfMonth(@year,8, 'Monday',1),'Holiday','Civic Holiday' UNION ALL
    select dbo.NthDayOfMonth(@year,9, 'Monday',1),'Holiday','Labour Day' UNION ALL
    select dbo.NthDayofMonth(@year,10,'Monday',2),'Holiday','Thanksgiving' UNION ALL
    select convert(varchar,@year)+'-11-11' ,'Holiday','Rememberance Day'UNION ALL
    select convert(varchar,@year)+'-12-25' ,'Holiday','Christmas Day' UNION ALL
    select convert(varchar,@year)+'-12-26' ,'Holiday','Boxing Day' UNION ALL
    SELECT CONVERT(DATE,CONVERT(VARCHAR,@year) + '-0'+CONVERT(VARCHAR, FLOOR((((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30) - (FLOOR((@year % 19.0 + (11 * ((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30))) / 319)) + ((((2 * FLOOR((@year / 100.0)) % 4) + (2*((@year % 100) / 4))) - ((@year % 100) % 4) - ((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30) + (FLOOR((@year % 19.0 + (11 * ((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30))) / 319)) +32) % 7) + 90) / 25))+'-'+CONVERT(VARCHAR,CONVERT(INT,(((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30) - (FLOOR((@year % 19.0 + (11 * ((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30))) / 319)) + ((((2 * FLOOR((@year / 100.0)) % 4) + (2*((@year % 100) / 4))) - ((@year % 100) % 4) - ((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30) + (FLOOR((@year % 19.0 + (11 * ((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30))) / 319)) +32) % 7) + (FLOOR((((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30) - (FLOOR((@year % 19.0 + (11 * ((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30))) / 319)) + ((((2 * FLOOR((@year / 100.0)) % 4) + (2*((@year % 100) / 4))) - ((@year % 100) % 4) - ((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30) + (FLOOR((@year % 19.0 + (11 * ((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30))) / 319)) +32) % 7) + 90) / 25)) + 19) % 32,0))),'Holiday','Easter Sunday' UNION ALL
    SELECT DATEADD(DAY,-2,CONVERT(DATE,CONVERT(VARCHAR,@year) + '-0'+CONVERT(VARCHAR, FLOOR((((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30) - (FLOOR((@year % 19.0 + (11 * ((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30))) / 319)) + ((((2 * FLOOR((@year / 100.0)) % 4) + (2*((@year % 100) / 4))) - ((@year % 100) % 4) - ((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30) + (FLOOR((@year % 19.0 + (11 * ((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30))) / 319)) +32) % 7) + 90) / 25))+'-'+CONVERT(VARCHAR,CONVERT(INT,(((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30) - (FLOOR((@year % 19.0 + (11 * ((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30))) / 319)) + ((((2 * FLOOR((@year / 100.0)) % 4) + (2*((@year % 100) / 4))) - ((@year % 100) % 4) - ((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30) + (FLOOR((@year % 19.0 + (11 * ((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30))) / 319)) +32) % 7) + (FLOOR((((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30) - (FLOOR((@year % 19.0 + (11 * ((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30))) / 319)) + ((((2 * FLOOR((@year / 100.0)) % 4) + (2*((@year % 100) / 4))) - ((@year % 100) % 4) - ((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30) + (FLOOR((@year % 19.0 + (11 * ((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30))) / 319)) +32) % 7) + 90) / 25)) + 19) % 32,0)))),'Holiday','Good Friday' UNION ALL
    SELECT DATEADD(DAY,1,CONVERT(DATE,CONVERT(VARCHAR,@year) + '-0'+CONVERT(VARCHAR, FLOOR((((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30) - (FLOOR((@year % 19.0 + (11 * ((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30))) / 319)) + ((((2 * FLOOR((@year / 100.0)) % 4) + (2*((@year % 100) / 4))) - ((@year % 100) % 4) - ((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30) + (FLOOR((@year % 19.0 + (11 * ((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30))) / 319)) +32) % 7) + 90) / 25))+'-'+CONVERT(VARCHAR,CONVERT(INT,(((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30) - (FLOOR((@year % 19.0 + (11 * ((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30))) / 319)) + ((((2 * FLOOR((@year / 100.0)) % 4) + (2*((@year % 100) / 4))) - ((@year % 100) % 4) - ((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30) + (FLOOR((@year % 19.0 + (11 * ((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30))) / 319)) +32) % 7) + (FLOOR((((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30) - (FLOOR((@year % 19.0 + (11 * ((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30))) / 319)) + ((((2 * FLOOR((@year / 100.0)) % 4) + (2*((@year % 100) / 4))) - ((@year % 100) % 4) - ((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30) + (FLOOR((@year % 19.0 + (11 * ((( (19 * (@year % 19.0)) + FLOOR(@year / 100.0)) - FLOOR((@year / 100.0) / 4) - FLOOR((8 * (@year / 100.0) + 13) / 25.0) + 15) % 30))) / 319)) +32) % 7) + 90) / 25)) + 19) % 32,0)))),'Holiday','Easter Monday'
    update @table
    set date =
    case when MONTH(date) = 12 AND name != 'Boxing Day' and datepart(weekday,date) = 7 then dateadd(day,2,date)
    when MONTH(date) = 12 AND name != 'Boxing Day' and datepart(weekday,date) = 1 then dateadd(day,1,date)
    when MONTH(date) = 12 AND name = 'Boxing Day' and datepart(weekday,date) = 7 then dateadd(day,2,date)
    when MONTH(date) = 12 AND name = 'Boxing Day' and datepart(weekday,date) = 1 then dateadd(day,2,date)
    when MONTH(date) = 12 AND name = 'Boxing Day' and datepart(weekday,date) = 2 then dateadd(day,1,date)
    else date
    end
    return
    end
    GO
    create function Dates(@date datetime)
    returns @table table
    now datetime,
    today datetime,
    Month_start datetime,
    Month_end datetime,
    Prev_Month_Start datetime,
    Prev_Month_End datetime,
    Week_Start datetime,
    Week_End datetime,
    Prev_Week_Start datetime,
    Prev_Week_End datetime,
    Quarter_Start datetime,
    Quarter_End datetime,
    Prev_Quarter_Start datetime,
    Prev_Quarter_End datetime,
    Year_Start datetime,
    Year_End datetime,
    Prev_Year_Start datetime,
    Prev_Year_End datetime,
    Month_End_TS datetime,
    Prev_Month_End_TS datetime,
    Week_End_TS datetime,
    Prev_Week_End_TS datetime,
    Quarter_End_TS datetime,
    Prev_Quarter_End_TS datetime,
    Year_End_TS datetime,
    Prev_Year_End_TS datetime,
    Year smallint,
    Month smallint,
    Day smallint,
    Month_Name varchar(15),
    Day_Name varchar(15),
    WD SMALLINT,
    Week INT,
    isHoliday bit
    as
    begin
    if @date IS NULL set @date = getdate()
    insert into @table
    select
    @date as now,
    convert(datetime,convert(varchar,@date,101)) as today,
    dateadd(day,0-day(@date)+1,convert(datetime,convert(varchar,@date,101))) as Month_Start,
    dateadd(day,-1,dateadd(month,1,dateadd(day,0-day(@date)+1,convert(datetime,convert(varchar,@date,101))))) as Month_end,
    dateadd(month,-1,dateadd(day,0-day(@date)+1,convert(datetime,convert(varchar,@date,101)))) as Prev_Month_start,
    dateadd(day,-1-day(@date)+1,convert(datetime,convert(varchar,@date,101))) as Prev_Month_End,
    dateadd(day,1-datepart(dw,@date),convert(datetime,convert(varchar,@date,101))) as Week_Start,
    dateadd(day,7-datepart(dw,@date),convert(datetime,convert(varchar,@date,101))) as Week_End,
    dateadd(day,-6-datepart(dw,@date),convert(datetime,convert(varchar,@date,101))) as Prev_Week_Start,
    dateadd(day,0-datepart(dw,@date),convert(datetime,convert(varchar,@date,101))) as Prev_Week_End,
    convert(datetime,convert(varchar,year(@date)) +'-'+ right('0'+convert(varchar,((datepart(QUARTER,@date)-1)*3)+1),2)+'-01') as quarter_start,
    dateadd(day,-1,dateadd(quarter,1,convert(datetime,convert(varchar,year(@date)) +'-'+ right('0'+convert(varchar,((datepart(QUARTER,@date)-1)*3)+1),2)+'-01'))) as quarter_end,
    convert(datetime,convert(varchar,year(dateadd(quarter,-1,@date))) +'-'+ right('0'+convert(varchar,((datepart(QUARTER,dateadd(quarter,-1,@date))-1)*3)+1),2)+'-01') as prev_quarter_start,
    dateadd(day,-1,dateadd(quarter,1,convert(datetime,convert(varchar,year(dateadd(quarter,-1,@date))) +'-'+ right('0'+convert(varchar,((datepart(QUARTER,dateadd(quarter,-1,@date))-1)*3)+1),2)+'-01'))) as prev_quarter_end,
    dateadd(day,1-day(@date),dateadd(month,1-month(@date),convert(varchar,@date,101))) as Year_Start,
    dateadd(year,1,dateadd(day,0-day(@date),dateadd(month,1-month(@date),convert(varchar,@date,101)))) as Year_End,
    dateadd(year,-1,dateadd(day,1-day(@date),dateadd(month,1-month(@date),convert(varchar,@date,101)))) as Prev_Year_Start,
    dateadd(year,-1,dateadd(year,1,dateadd(day,0-day(@date),dateadd(month,1-month(@date),convert(varchar,@date,101))))) as Prev_Year_End,
    dateadd(ms,-3,dateadd(day,0,dateadd(month,1,dateadd(day,0-day(@date)+1,convert(datetime,convert(varchar,@date,101)))))) as Month_End_Ts,
    dateadd(ms,-3,dateadd(day,-1-day(@date)+2,convert(datetime,convert(varchar,@date,101)))) as Prev_Month_End_TS,
    dateadd(ms,-3,dateadd(day,8-datepart(dw,@date),convert(datetime,convert(varchar,@date,101)))) as Week_End_TS,
    dateadd(ms,-3,dateadd(day,1-datepart(dw,@date),convert(datetime,convert(varchar,@date,101)))) as Prev_Week_End_TS,
    dateadd(ms,-3,dateadd(day,0,dateadd(quarter,1,convert(datetime,convert(varchar,year(@date)) +'-'+ right('0'+convert(varchar,((datepart(QUARTER,@date)-1)*3)+1),2)+'-01')))) as quarter_end_TS,
    dateadd(ms,-3,dateadd(day,0,dateadd(quarter,1,convert(datetime,convert(varchar,year(dateadd(quarter,-1,@date))) +'-'+ right('0'+convert(varchar,((datepart(QUARTER,dateadd(quarter,-1,@date))-1)*3)+1),2)+'-01')))) as prev_quarter_end_TS,
    dateadd(ms,-3,dateadd(year,1,dateadd(day,1-day(@date),dateadd(month,1-month(@date),convert(varchar,@date,101))))) as Year_End_TS,
    dateadd(ms,-3,dateadd(day,1-day(@date),dateadd(month,1-month(@date),convert(varchar,@date,101)))) as Prev_Year_End_TS,
    Year(@date) as Year,
    Month(@date) as Month,
    Day(@Date) as Day,
    datename(month,@Date) as Month_Name,
    datename(WEEKDAY,@date) as Day_Name,
    datepart(weekday,@date) as WD,
    DATEPART(WEEK,@date) AS Week,
    COALESCE((SELECT 1
    FROM dbo.Holidays(YEAR(@date)) h
    WHERE h.date = @date),0) AS isHoliday
    return
    end
    go
    The holidays function is set up for Saskatchewan right now, but its a small matter to adjust it to your region.
    You can then do this:
    DECLARE @calendar TABLE (date DATE)
    WHILE (SELECT COUNT(*) FROM @calendar) < 365
    BEGIN
    INSERT INTO @calendar (date)
    VALUES (DATEADD(day,1,(SELECT COALESCE(MAX(date),CURRENT_TIMESTAMP) FROM @calendar)))
    END
    SELECT MONTH(date) AS month, MIN(date) AS fbd
    FROM @calendar c
    CROSS APPLY dbo.Dates(c.date)
    WHERE DATEPART(DAY,c.date) NOT IN (1,7) AND isHoliday = 0
    GROUP BY MONTH(date)

  • Need Help Calculating Business Days AND omitting Holidays...

    Post Author: dkotenoglou
    CA Forum: Formula
    Thanks to the people here I was able to get a nice formula to help me calculate the amount of business days between two days.//Crystal syntax
    Local DateTimeVar d1 := ;
    Local DateTimeVar d2 := ;
    DateDiff ("d", d1, d2) -
         DateDiff ("ww", d1, d2, crSaturday) - 
         DateDiff ("ww", d1, d2, crSunday) This works great.  I wanted to add the ability to omit US Holidays.  Now this is a straight Crystal Reports install without an SQL backend so I cannot use any formulas there.Is there a parameter? I can use to manually create a table of dates to omit?  The only reason I ask is that our company was closed during the holidays so my day reports are really high. I do not mind typing a long list of days manually (12/24/2007, 12/25/2007, etc) but I need to know how to best integrate that list into the formula.  

    Post Author: V361
    CA Forum: Formula
    If you have CR XI, there is another example as well, in the sample reports,  look at feature examples, custom functions.rpt   this code is from that example.
    Function cdDateAddSkipHolidays (nWorkingDays As Number, startDateTime As DateTime) As DateTime    'the result = startDateTime + nWorkingDays + nHolidays (including weekends)    'the algorithm below also works when nWorkingDays is negative
        Dim totalDays    'give a rough estimate for total days. For each 5 work days there are 7    'days. Also add in an extra 2 weekend days to account for a partial week.    totalDays = Fix(nWorkingDays * 7 / 5 + 1) + 2
        Dim iteratedDiff    iteratedDiff = cdDateDiffSkipHolidays (startDateTime, startDateTime + totalDays)
        If (iteratedDiff >= nWorkingDays) Then        Do While iteratedDiff >= nWorkingDays            totalDays = totalDays - 1            iteratedDiff = cdDateDiffSkipHolidays (startDateTime, startDateTime + totalDays)        Loop        cdDateAddSkipHolidays = startDateTime + totalDays + 1    Else        Do While iteratedDiff < nWorkingDays            totalDays = totalDays + 1            iteratedDiff = cdDateDiffSkipHolidays (startDateTime, startDateTime + totalDays)        Loop         cdDateAddSkipHolidays = startDateTime + totalDays    End If
    End Function

  • How to set execution time of the step with business days in the workflow

    As we know, we can set how many days later the step should be execuated after previous step. now, the problem is how to set the business days (days except sunday and sataurday) for it. any one has good solution on it.

    Hi Nick,
    In order to find the Next working day you need to check for the Factory calendar days for eg, if a workitem has invoked today and if the Approver doesn't release the workitme for which u want to send a mail/reminder to the approver after say next 5or 6 working days, you need to create a function module.
    For eg: In case of Purchase order, if the approver doesn't release the PO .
    Create a Method saying "Next working day" , in which you will be passing the import parameters : PO, Factory calendar day and the sy-datum
    and export parameter : date.
    Create Input date and No of days as container elements of the Task and in the method create a Function module
    In case of PO, consider the Factory calendar key from the T001W  by joining the table EKPO there by passing the PO.
    then pass the date, No of days(say 5 days) and the Factory calendar key  to the "WDKAL_DATE_ADD_FKDAYS" , you will get the next working day of the employee.
    Don't forget to check the Binding properly.
    Do implement this logic and check the same.
    Regards
    Sharief

Maybe you are looking for

  • 24" LED display

    Hi I hope someone can help. I have a Jan 2008 Macpro (2nd Gen I think). I would like to buy the LED display which has the new mini display port.Can I have advise whether this display will work with my Macpro? If not can I buy an adaptor to link the m

  • Try to play video recorded with iphone4s and says tv connected video playing on tv HELP

    please help me i am no longer able to view videos on my 4s ???

  • I can't recover sent emails

    When I look for emails in the "Sent" mailbox, they are all marked with a message that indicates the mailbox is overstuffed. I have reviewed a number of previous emails to try and recover them. So far I have checked the contents of Sent Messages.mbox

  • When i open firefox, i get asked what program i want to use to open this file.

    when i open firefox, i get asked what program i want to use to open this file. i select firefox to open firefox, and it opens to - Index of file:///C:/Documents and Settings/HP_Administrator/- instead of my home page. this has been going on for month

  • Update batch for process order in change mode

    Hi All , I need to update the batch number(which will be external batch number given by me ) in COR2 (process order change) transaction ,under the tab Goods receipt . Is there any bapi which achieves this ?? pls reply Thanks .