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.

Similar Messages

  • How to get the data for last 3rd business day and also include saturday and sunday if its a wednesday?

    Hi All,
    I have a simple query which is below:-
    Declare @reportdate date
    set @reportdate= (DATEADD(dd,-5,getdate()))
    select * from dbo.Table
    where date IN (@reportdate)
    I need this query to pull the data for the last 3rd business day .So lets say today is monday then i need the data for last week wednesday which is 3 business days back from monday, if today is a tuesday it would be for last thursday ( as 3 business days for
    tuesday would be thursday). But if today is wednesday then i need to be last 3rd business day which is last friday and i also need to get the data for saturday and sunday.
    Can someone please help me how cani change my filter to do this?
    Please let me know if i am still unclear.
    Thanks

    Hi SqlDev12,
    Based on my understanding on your requirement, you can reference the below sample.
    CREATE TABLE BusinessTable
    Bdate DATE,
    Wd VARCHAR(10)
    ;WITH Cte(DT,WD) AS
    SELECT CAST('20150401' AS DATE),DATENAME(WEEKDAY,CAST('20150401' AS DATE))
    UNION ALL
    SELECT DATEADD(DAY,1,DT),DATENAME(WEEKDAY,DATEADD(DAY,1,DT)) FROM Cte
    WHERE DT<GETDATE()
    INSERT INTO BusinessTable SELECT * FROM Cte
    SELECT * FROM BusinessTable
    SET DATEFIRST 7 -- Set Sunday as the first day of a week
    DECLARE @givenDay DATE ='20150415' --Wednesday
    SELECT * FROM BusinessTable
    WHERE Bdate BETWEEN
    --For Monday and Sunday, select last wednesday
    (CASE WHEN DATEPART(WEEKDAY,@givenDay) IN(1,2) THEN DATEADD(DAY,2,DATEADD(WEEK,DATEDIFF(WEEK,0,@givenDay)-1,0))
    --For Tuesday and Wednesday, last week's Thursday and Friday
    WHEN DATEPART(WEEKDAY,@givenDay) IN(3,4) THEN DATEADD(DAY,-5,@givenDay)
    --For Thursday and Friday, current week's Monday and Tuesday
    WHEN DATEPART(WEEKDAY,@givenDay) IN(5,6) THEN DATEADD(DAY,-3,@givenDay)
    --For Saturday, current week's Wednesday
    ELSE DATEADD(DAY,2,DATEADD(WEEK,DATEDIFF(WEEK,0,@givenDay),0)) END)
    AND
    (CASE WHEN DATEPART(WEEKDAY,@givenDay) IN(1,2) THEN DATEADD(DAY,2,DATEADD(WEEK,DATEDIFF(WEEK,0,@givenDay)-1,0))
    WHEN DATEPART(WEEKDAY,@givenDay) IN(3) THEN DATEADD(DAY,-5,@givenDay)
    WHEN DATEPART(WEEKDAY,@givenDay) IN(4) THEN DATEADD(DAY,-3,@givenDay)
    WHEN DATEPART(WEEKDAY,@givenDay) IN(5,6) THEN DATEADD(DAY,-3,@givenDay)
    ELSE DATEADD(DAY,2,DATEADD(WEEK,DATEDIFF(WEEK,0,@givenDay),0)) END)
    DROP TABLE BusinessTable
    If you have any feedback on our support, you can click
    here.
    Eric Zhang
    TechNet Community Support

  • 5. We need additional time to process your transaction You should get an email from us by next business day. If you don't hear back from us, you can check your order status on your account page or call us at +1 800-585-0774. If you're not in North America

    Step 5.
    5. We need additional time to process your transaction You should get an email from us by next business day. If you don't hear back from us, you can check your order status on your account page or call us at +1 800-585-0774. If you're not in North America, you can look up a local number here. For now, check out all the great free features of Creative Cloud! Get started with trials
    I keep getting this.
    The Bank and Paypal states that Adobe needs to process my transaction twice.
    I have no order number/ no status nor contact from Adobe. I called customer service and he transferred me to sales where the phone rang with no answer.

    Since this is an open forum, not Adobe support... you need to contact Adobe staff to help
    Adobe contact information - http://helpx.adobe.com/contact.html
    -Select your product and what you need help with
    -Click on the blue box "Still need help? Contact us"
    -or by telephone http://helpx.adobe.com/x-productkb/global/phone-support-orders.html

  • Calculating hours in numerical formats between 2 business days, calculated column

    Hi there,
    I need to calculate how many hours are between 2 days only including business days, outputting in numerical format (ex. 7.3). 
    I've been using this formula to output how many weekdays are between 2 days.
    =IF(AND((WEEKDAY(CompletedTimeStamp,2))<(WEEKDAY(,2)),((WEEKDAY(Created,2))-(WEEKDAY(CompletedTimeStamp,2)))>1),(((DATEDIF(Created,CompletedTimeStamp,"D")+1))-(FLOOR((DATEDIF(Created,CompletedTimeStamp,"D")+1)/7,1)*2)-2),(((DATEDIF(Created,CompletedTimeStamp,"D")+1))-(FLOOR((DATEDIF(Created,CompletedTimeStamp,"D")+1)/7,1)*2)))
    The problem with this is if the 2 dates are on the same day, it outputs "1". I need it to output the amount of hours then / by 24 to give me ".7"  instead.
    Is there anything I can do to convert this current formula to give me hours instead of days?
    Thanks,
    Terence

    The DATEDIF is rounding to the nearest day.
    Try this:
    =IF(AND((WEEKDAY(CompletedTimeStamp,2))<(WEEKDAY(,2)),((WEEKDAY(Created,2))-(WEEKDAY(CompletedTimeStamp,2)))>1),(((CompletedTimeStamp-Created+1))-(FLOOR((CompletedTimeStamp-Created+1)/7,1)*2)-2),(((CompletedTimeStamp-Created+1))-(FLOOR((CompletedTimeStamp-Created+1)/7,1)*2)))
    -1
    Then above will return fractions of days, i.e.  5.5 days. Multiply this by 24 for hours.
    I think there is a extra "+1" in the above example somewhere, so I added a minus 1 to get back the correct value.
    Hi.. Mike.. I am trying to use this calcuation.. its renndering "time being used 3.3".. I need it to calcuate a work day as 8 hrs  so if
    Start Date= 9/12/2014 9:00am
    End Date= 9/16/2014 5:00 pm
    should be 3 (8 hr work days)  any way I can fix this?
    Thanks in advance for your help.
    Mike Smith TechTrainingNotes.blogspot.com

  • Service Requests-Business days when year changes

    Hi All,
    I am trying to calculate for how long a SR has been open in business days only.
    I have successfully used Mike Lairson's formula for the last 9 months but it seems it cannot cope with year changes. If the begin data is in 2009 and the end date in 2010, the results are not correct anymore.
    E.G. For an SR that was opened on 12/30/2009 and closed on 01/05/2010 should return 5 business days but it is actually returning 110.
    The syntax that I used so far is:
    (CASE
    /* Convert Sunday to the Business Day Of the Year */
    WHEN DAYOFWEEK("Service Request"."Closed Date and Time") = 1
    THEN (DAYOFYEAR("Service Request"."Closed Date and Time") - WEEK("Service Request"."Closed Date and Time")) -
    (WEEK("Service Request"."Closed Date and Time") - 2)
    /* Convert Saturday to the Business Day Of the Year */
    WHEN DAYOFWEEK("Service Request"."Closed Date and Time") = 7
    THEN (DAYOFYEAR("Service Request"."Closed Date and Time") - WEEK("Service Request"."Closed Date and Time")) -
    (WEEK("Service Request"."Closed Date and Time") - 1)
    /* Convert Mon-Fri to the Business Day Of the Year */
    ELSE (DAYOFYEAR("Service Request"."Closed Date and Time") -
    WEEK("Service Request"."Closed Date and Time")) +
    (2 - WEEK("Service Request"."Closed Date and Time")) END)
    (CASE
    /* Convert Sunday to the Business Day Of the Year */
    WHEN DAYOFWEEK("Service Request"."Opened Date") = 1
    THEN (DAYOFYEAR("Service Request"."Opened Date") -
    WEEK("Service Request"."Opened Date")) -
    (WEEK("Service Request"."Opened Date") - 2)
    /* Convert Saturday to the Business Day Of the Year */
    WHEN DAYOFWEEK("Service Request"."Opened Date") = 7
    THEN (DAYOFYEAR("Service Request"."Opened Date") -
    WEEK("Service Request"."Opened Date")) -
    (WEEK("Service Request"."Opened Date") - 1)
    /* Convert Mon-Fri to the Business Day Of the Year */
    ELSE (DAYOFYEAR("Service Request"."Opened Date") -
    WEEK("Service Request"."Opened Date")) +
    (2 - WEEK("Service Request"."Opened Date"))
    END)
    +
    /* Adjust for Year Change */
    (365 * (YEAR("Service Request"."Closed Date and Time") -
    YEAR("Service Request"."Opened Date")))
    Any ideea or hint would be highly appreciated.
    Thank you.
    Regards,
    Dorin
    Edited by: user805960 on 06.01.2010 07:07

    Hi,
    i used this formula to find out the days it calculates between 31/12/2009 and 01/01/2010, the result it gave was 106 days.
    So i subtracted 106 from 365 days (365-106=259)in the formula, the formula is now giving the correct values.
    I think we have to add the total working days and not the no.of days in a year.
    Please can you all reconfirm the results.
    Thanks
    Neena
    Edited by: NNK on Jan 11, 2010 3:16 PM

  • I am using numbers in the new iWork. Just bought it 10 days back. I am not able to figure out how to add serial umbers from 1 to 100( for example) also i need to freeze the top header like in windows so that we can browse down without the heading going of

    i am using numbers in the new iWork. Just bought it 10 days back. I am not able to figure out how to add serial umbers from 1 to 100( for example) also i need to freeze the top header like in windows so that we can browse down without the heading going off. Can some one help?

    Hi Jay,
    Be aware that "Freeze Header Rows" and "Freeze Header Columns" apply only to rows and columns that are Header rows or Header columns. You can have up to five Header rows, Five Header Columns (and five Footer rows) on a Numbers Table.
    "Header rows" is a special designation. Besides being able to be frozen, Header and Footer rows are not included in formulas referencing whole columns, making it possible to place formulas such as =SUM(B) at the top (or bottom) of column B without causing a self-reference error, These designated rows are also not included in sorts of the rows in a table.
    Regards,
    Barry

  • 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 to Schedule a Report to Run on a Specific Business Day and Not on the Weekend

    Hi,
    Is there a way to schedule a Webi report to run on a specific Business Day? For example, if I wanted a report to run on the 3rd day of every month, but when the 3rd day for a particular month landed on a Saturday or Sunday, then Monday would automatically be chosen instead. Is that possible?
    Thanks,
    Michael

    Hi Michael,
    You can do that by selecting the calendar option while scheduling the report and manually selecting the 3rd day of every month and when the 3rd day for a particular month landed on a Saturday or Sunday, then select the next Monday.
    I dont see any option available for this scenario directly in BO.
    Regards
    Sri Harsha

  • I bought new i phone 5 3 days back, after that asked for new update which is 6.1.4, after updating my iphone i am not able to use cellular data services. I called up data provider, they says its the problem with new software update. There is no option add

    I bought new i phone 5 3 days back, after that asked for new update which is 6.1.4, after updating my iphone i am not able to use cellular data services. I called up data provider, they says its the problem with new software update. There is no option add APN. Now when i switch to safari its showing you are not subscribed for cellular data. But I am able to use data on other phone.
    Will you please help me in this regard?
    Another issue, since i bought my new iphone there is dust inside back main camera.
    Your advises are highly appreciated.

    Hey Shaiju isac,
    I'd take a look at the following article, it'll guide you though steps to you troubleshoot cellular data issues on your iPhone:
    iPhone: Troubleshooting a cellular data connection
    http://support.apple.com/kb/ts3780
    Cheers,
    David

  • How to: Schedule a job to run on the first business day of the month

    In Oracle 10.2.0.3, is there a way to schedule a repeating job to run on the first business day of the month? For example, if the first of the month falls on a weekend (such as Saturday, 11/01/2008), I would like the job to run automatically on Monday (for example, 11/03/2008) instead.

    set serveroutput on
    begin
      print_dates('FREQ=MONTHLY;BYDAY=MON,TUE,WED,THU,FRI;BYSETPOS=1;',
          to_timestamp_tz('01-JAN-2008 12:00:00','DD-MON-YYYY HH24:MI:SS'), 12);
    end;
    Gives:
    TUE 01-JAN-2008 (001-01) 12:00:00 -07:00 -07:00
    FRI 01-FEB-2008 (032-05) 12:00:00 -07:00 -07:00
    MON 03-MAR-2008 (063-10) 12:00:00 -07:00 -07:00
    TUE 01-APR-2008 (092-14) 12:00:00 -07:00 -07:00
    THU 01-MAY-2008 (122-18) 12:00:00 -07:00 -07:00
    MON 02-JUN-2008 (154-23) 12:00:00 -07:00 -07:00
    TUE 01-JUL-2008 (183-27) 12:00:00 -07:00 -07:00
    FRI 01-AUG-2008 (214-31) 12:00:00 -07:00 -07:00
    MON 01-SEP-2008 (245-36) 12:00:00 -07:00 -07:00
    WED 01-OCT-2008 (275-40) 12:00:00 -07:00 -07:00
    MON 03-NOV-2008 (308-45) 12:00:00 -07:00 -07:00
    MON 01-DEC-2008 (336-49) 12:00:00 -07:00 -07:00
    and the print_dates function is (10.2):
    create or replace procedure print_dates
      cal_string in varchar2,
      start_date in timestamp with time zone,
      nr_of_dates in pls_integer
    is
      date_after timestamp with time zone := start_date - interval '1' second;
      next_execution_date timestamp with time zone;
    begin
      dbms_output.put_line('  -->');
      for i in 1 .. nr_of_dates
      loop
        dbms_scheduler.evaluate_calendar_string
         (cal_string, start_date, date_after, next_execution_date);
        dbms_output.put_line(to_char(next_execution_date,
                        'DY DD-MON-YYYY (DDD-IW) HH24:MI:SS TZD TZH TZR'));
        date_after := next_execution_date;
      end loop;
    end;
    [\pre]                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • I got my i phone4s few days back and i created an apple id with a credit card and when i go to the appstore to purchase apps,all have and message stating that "this app is no longer availabe"..how do i fix this issue?im from singapore by the way

    i got my i phone4s few days back and i created an apple id with a credit card and when i go to the appstore to purchase apps,all have and message stating that "this app is no longer available"..how do i fix this issue?im from singapore by the way

    If it is longer available then you can't get the app on your phone.

  • Can I get a Calendar event to repeat every 4 business days?

    I go to a school with a 4-day timetable; that is to say, classes repeat in the same order every 4 days. Is there any way to get events in Calendar to repeat every 4 business days?

    I just tested and here is what I get...

  • Please i did pay to renew my ios developer account and you sent me an email to reply within 2 business days, but nothing happend yet. may i know what is the problem?

    please i did pay to renew my ios developer account and you sent me an email to reply within 2 business days, but nothing happend yet. may i know what is the problem?

    This is primarily a user-to-user support forum and not related to developers. The following link has information about checking your program enrollment:  https://developer.apple.com/support/ios/enrollment.html#howcanicheckstatus
    If that doesn't help, there is a "Contact Us" button at the bottom of the page in the above link.

  • Calculation of due date based on Business Days for FICA documents

    Hi All,
    I am working on project where SD - FICA integration is in picture. We post some charges through SD and FICA document gets posted on relevant Contract Account.
    Normally we create Sales Order using transaction VA01 and then we do Billing for this Sales Order through VF01. After billng is done, FICA document automatically gets generated.
    We have following requirement to be fulfilled.
    For the SD bills posted as above, I want to calculate due date of these bills based on Business Days for FICA document generated (SAP Standard calculate due date based on Calander days). We can use factory calander for calculating business days in relevant function module.
    I have checked in the system and it seems that event 1330 ( FM - ISU_DUE_DATE_DETERMINE) is not working in this scenario. Is there any other FM which I can use?
    Can anyone help me on this?
    Regards,
    Pradeep

    Hello Praeva ,
    The event 1330 has a sample FM FKK_SAMPLE_1330. It doesnt even have a Standard Function Module.
    You need to create a Installation-Specific FM and put your code to determine the Due Date based on the logic.
    Rgds
    Ram Kumar.

  • I have updated my mac from snow leopard to mountain lion 3 days back. I had some important data in my library folder and it got overwritten. Is there any way i can get the data back from my snow leopard library folder?

    I have updated my mac from snow leopard to mountain lion 3 days back. I had some important data in my library folder and it got overwritten. Is there any way i can get the data back from my snow leopard library folder?
    I tried mackeeper to recover files but it could not. Any other way any one has tried to recover a system library folder after OS upgrade?

    No, it doesn't store a clone. You would have needed to make one with either SuperDuper or CarbonCopy Cloner.
    If the files were in your ~/Library folder then they may still be there. As I said, you can access it by
    going to your Finder "Go" menu hold the option key to choose "Library". I wouldn't think an upgrade would overwrite anything in ~/Library.
    If you have a Time Machine backup you may also be able to use that to retrieve them.

Maybe you are looking for