Calculate the last business day

Hello

I use Oracle Database 11.2.1 and wants to return to the last day of work (JJ/MM/AAAA).

Working days Monday to Friday delivery

for example on Sunday, 18 June 2000, the returned value would be Thursday, June 15, 2000

sliderrules wrote:
I wanted to say the days of the week

for example, Monday, May 13, 2013 would return 10/05/2013
Tuesday, May 14, 2013 would return 13/05/2013 etc.

What the earlier query?

SQL> with t as
  2      (
  3      select to_date('13/05/2013 ','dd/mm/yyyy') dt
  4      from dual
  5      union all
  6      select to_date('14/05/2013 ','dd/mm/yyyy') dt
  7      from dual
  8      )
  9      select dt,dt -
 10             case to_char(dt,'fmday','nls_language=english')
 11                         when 'sunday' then 2
 12                 when 'monday' then 3
 13                else 1
 14            end last_w_day
 15     from t;

DT        LAST_W_DA
--------- ---------
13-MAY-13 10-MAY-13
14-MAY-13 13-MAY-13

Tags: Database

Similar Questions

  • How to get the last business day of the previous month?

    Hi all

    We need the user as below,

    If the user select 18 June 2015 ' quick dashboard as the input value, and then they want to see last month last day of work (business date: 29-may-2015) amount in report, if you have an idea please share with us.thanks

    Note:

    use under request we can able to get the last day of the previous month, we want to for the last business day of the last month, based on the date of entry of the user?

    TIMESTAMPADD (SQL_TSI_DAY,-(1), TIMESTAMPADD (SQL_TSI_DAY, DAYOFMONTH ("DIM_TIME". ("" DataDate ") *-(1) + 1,"DIM_TIME ". (("" DataDate "))

    Thank you

    Deva

    Try this,

    case when Dayofweek (timestampadd (sql_tsi_day, Dayofmonth(Date '2015-06-15') *-1, Date ' 2015-06-15')) = 1 then timestampadd (sql_tsi_day, (Dayofmonth(Date '2015-06-15') *-1)-2, Date '' 2015-06-15) when Dayofweek (timestampadd (sql_tsi_day, Dayofmonth(Date '2015-06-15') *-1, Date ' 2015-06-15')) = 7 then timestampadd (sql_tsi_day, Dayofmonth(Date '2015-06-15') *-1-1, Date '' 2015-06-15) another timestampadd (sql_tsi_day, Dayofmonth(Date '2015-06-15') *-1, Date ' 2015-06-15') end

    As Ftsiot said in this post, it will work only to exclude the sat and Sun. Another one if you want to exclude regional holiday, you may need a calendar in DB table.

    Thank you

    AJ

  • calculate data for the last 30 days according to the date of sys

    SELECT DT, ITEMCODE, ITEMNAME, QTY
    FROM   TABLE1
    In above given the query, how do I calculate the details of the amount of the last 30 days, APR, MAY, and JUNE

    As the month during JULY, August, the amount of detail is required for the last 30 days (from sysdate), MAY, JUNE, July

    Please suggest.

    Yogesh

    Published by: user12957777 on July 28, 2010 03:16

    Hello

    CASE expressions can filter data in specific columns:

    SELECT     SUM ( CASE
                WHEN dt >= ADD_MONTHS ( TRUNC (SYSDATE, 'MONTH')
                             , -3
                             )
                AND  dt <  ADD_MONTHS ( TRUNC (SYSDATE, 'MONTH')
                             , -2
                             )
                THEN qty
               END
             )          AS third_month
    ,     SUM ( CASE
                WHEN dt >= ADD_MONTHS ( TRUNC (SYSDATE, 'MONTH')
                             , -2
                             )
                AND  dt <  ADD_MONTHS ( TRUNC (SYSDATE, 'MONTH')
                             , -1
                             )
                THEN qty
               END
             )          AS second_month
    ,     SUM ( CASE
                WHEN dt >= ADD_MONTHS ( TRUNC (SYSDATE, 'MONTH')
                             , -1
                             )
                AND  dt <               TRUNC (SYSDATE, 'MONTH')
                THEN qty
               END
             )          AS last_month
    ,     SUM ( CASE
                WHEN dt >= TRUNC (SYSDATE) - 30
                AND  dt <  TRUNC (SYSDATE)
                THEN qty
               END
             )          AS last_30_days
    FROM     table1
    ;
    

    You can do this with GROUP BY, in addition, if you want to separate for each itemname (for example) lines.

    I guess some things, like what do you mean by the last 30 days.

    If you wish to post a few 9creation TABLE or INSERT sample data) and the results you want from this data, then I could test this.

  • PL/SQL function to calculate the non-working days

    Hello

    I have the following pl/sql function which generates a number of days between two selected dates (i.e. excluding weekends). However, I also need to exclude specific holidays - day of Christmas etc. These holiday dates are stored in a table in our database (11 GR 2) called "HOLIDAY".

    How can I integrate the holidays which is held in the table of holidays in the following query to exclude these dates as well? I know how to write a separate funtion pl/sql for a number of days between two dates using SELECT... BUT I can't work out how to bring together them in a single query.

    Could someone show me how with the pl/sql / dates below please?

    Example of HOLIDAY table below.

    Thank you!

    TP

    create or replace
    function WORKING_DAYS (pi_start_date in date, pi_end_date in date) return integer
    
    is
    
    v_start_date date :=pi_start_date;
    v_end_date date:=pi_end_date;
    v_count integer:=0;
    
    begin
    
    while v_start_date <= v_end_date
          loop
                            if to_char(v_start_date,'D') not in ('6','7')                    
                            then
                            v_count := v_count+1;                       
                            end if;
                           
                    v_start_date:=v_start_date+1;
                   
          end loop;
         
    return v_count;
    
    end;
    
    

    (select '10-Apr-2013' as NWD from dual union all
    select '06-May-2013' from dual union all
    select '27-May-2013' from dual union all
    select '26-Aug-2013' from dual union all
    select '26-Dec-2013' from dual union all
    select '25-Dec-2013' from dual union all
    select '01-Jan-2014' from dual union all
    select '18-Apr-2014' from dual union all
    select '21-Apr-2014' from dual union all
    select '05-May-2014' from dual union all
    select '26-May-2014' from dual union all
    select '25-Aug-2014' from dual union all
    select '25-Dec-2014' from dual union all
    select '26-Dec-2014' from dual) HOLIDAYS
    

    Hello

    the link is on MOSC, not OTN... Here's a copy:

    This function calculates the number of days between two dates, ignoring weekends and holidays (if requested and if the holidays are stored in a table)

    I give an example of table 'public_holiday' with sample data, but users must ensure that their table contains the relevant data (all holidays within the maximum range of use of the service)

    CREATE TABLE public_holiday (calendar_day, DATE, text VARCHAR2 (30));

    FUNCTION to CREATE or REPLACE nb_days (p_date_from IN DATE

    p_date_to DATE by DEFAULT TRUNC (sysdate)

    , p_public_holidays in CHAR DEFAULT 'Y '.

    ) RETURN NUMBER

    DEFINE AUTHID

    AS

    /*********************************************************************/

    / * Author: Bruno Vroman * /.

    / * Created: 23-AUG-2012 * /.

    / * Last updated: 23-AUG-2012 * /.

    / * Object: to calculate the number of days between 2 dates, to the exclusion of * /.

    / * Saturday and Sunday, but also "holidays" If the * /.

    / * argument 'p_public_holidays' = 'Y ' * /.

    / * Support: p_date_from<= p_date_to                             ="">

    / * component ' hour min dry "ignored (just counting days) * /.

    /* First step:                                                       */

    / * the calendar days between 2 days * /.

    / Remove 2 days for each "week" and 0 or 1 extra day * /.

    / * function to a condition "complex" mix day of first week * /.

    / * and the number of days when full remaining weeks are removed * /.

    / * (set up once for all, for example if there is 3 days and the * /)

    (/ * first day is a Thursday, there is 1 "Sat/Sun" to subtract) * /.

    / * Second step: If 'p_public_holidays' = 'Y': other * /.

    / * days, do not count holidays.                         */

    / Holiday everyday are defined in a table "public_holiday" * /.

    / * Note: there may be holidays defined on Saturday/Sunday.       */

    /*********************************************************************/

    l_result NUMBER;

    l_from DATE;

    l_to DATE;

    l_case tank (4);

    BEGIN

    l_from: = TRUNC (p_date_from);

    l_to: = TRUNC (p_date_to);

    l_case: = TO_CHAR (l_from, 'Dy', 'NLS_DATE_LANGUAGE = English').

    To_char (MOD (l_to - l_from + 1, 7));

    l_result: = l_to - l_from + 1

    -TRUNC ((l_to-l_from + 1) / 7) * 2

    -CASE

    WHEN l_case IN ('Mon6', 'Tue5', 'Wed4', 'Thu3', 'Fri2'

    , "Sat1", "Sun1", "Sun2', 'Sun3", "Sun4".

    , "Sun5', 'Sun6.

    )

    THEN 1

    WHEN l_case IN ('Tue6', 'Wed5', 'Wed6', 'Thu4', "Thu5"

    , 'Thu6', 'Fri3', 'Fri4', 'Fri5', 'Fri6 '.

    , "Sat2", "Sat3', 'Sat4', 'Sat5", "Sat6.

    )

    THEN 2

    0 OTHERWISE

    END

    ;

    IF SUPERIOR (p_public_holidays) = "Y".

    THEN

    SELECT l_result - COUNT (*)

    IN l_result

    OF public_holiday p

    WHERE p.calendar_day > = l_from

    AND p.calendar_day<=>

    AND SUBSTR (TO_CHAR (p.calendar_day

    , "Dy".

    'NLS_DATE_LANGUAGE = English'

    )

    , 1, 1 ) != 'S'

    ;

    END IF;

    RETURN l_result;

    EXCEPTION

    WHILE OTHERS

    THEN

    DBMS_OUTPUT. Put_line (' CTF nb_days (' |))

    To_char (p_date_from, "MON-DD-YYYY"). ', ' ||

    To_char (p_date_to, "MON-DD-YYYY"). ', ' ||

    p_public_holidays | ' ) : ' || SQLERRM

    );

    LIFT;

    END nb_days;

    /

    REM

    REM example:

    REM A) fill out the 'public_holidays '.

    REM

    TRUNCATE TABLE public_holiday;

    INSERT INTO public_holiday VALUES (DATE ' 2012-01-01', ' new year (a Sunday)');

    INSERT INTO public_holiday VALUES (DATE '' 2012-01-03, "for example");

    REM (insert other days...)

    COMMIT;

    Call the function for some pairs of dates of REM B)

    REM nb1: remove only Sat/Sun

    REM nb2: also remove holidays

    REM

    ALTER SESSION SET nls_date_format ='Dy DD-MON-YY';

    WITH some_dates AS

    (SELECT DATE ' 2011-12-29'd dual FROM

    UNION ALL SELECT DATE ' 2012-01-08' FROM dual

    UNION ALL SELECT DATE ' 2012-01-10' FROM dual

    )

    SELECT d1.d 'FROM '.

    , d2.d ' to THE '.

    , nb_days (d1.d, d2.d, ' don't) nb1

    , nb_days (d1.d, d2.d, 'Y') nb2

    OF some_dates d1

    some_dates d2

    WHERE d1.d<=>

    ORDER BY nb1, nb2, d1.d

    ;

    GO TO NB1 NB2

    ------------- ------------- ---- ----

    Monday, January 8, 12 Monday, January 8, 12 0 0

    Friday, December 29, 11 Friday, December 29, 11 1 1

    Wednesday, January 10, 12 Wednesday, January 10, 12 1 1

    Monday, January 8, 12 Wednesday, January 10, 12 2 2

    Friday, December 29, 11 Monday, January 8, 12 7 6

    Friday, December 29, 11 Wednesday, January 10, 12 9 8

    Hope that this could be useful, but note that this code has not been completely tested, so check and test before you trust it (in the case of any questions, please post a comment)

    Bruno Vroman.

    Best regards

    Bruno

  • Remove the last 35 days of a table data

    Hello

    I had a table to n days of data. I need to remove the last 35 days of data. My table has consecutive dates i.e. There were no load weekend or holidays...

    (1) Using INTERVAL command can simply calculate the difference. So it won't work.

    (2) I can use RANK to find the sequence. Is there a better way to write a logic to delete?.

    concerning

    KVB

    PurveshK,

    I think you have the right idea. Just get the ID of the innermost query.

    This should be quite effective, especially if there is an index on the date.

    drop table t;

    create table t:

    Select trunc (sysdate) - level * 2 double dt connect by level<=>

    delete t

    where rowid in)

    Select rn

    de)

    Select the rowid rn, dense_rank() over (order by dt desc) dr

    t

    )

    where dr<=>

    );

    Post edited by: StewAshton:

    Furthermore, the date field must be NOT NULL for the index be used - or even add WHERE DATE IS NOT NULL to the innermost query.

  • Calculate the difference in days between two Dates

    Hello

    I'm trying to understand how to calculate the difference in days between two dates using JavaScript in LiveCycle. (Minimum = JavaScript knowledge)

    Where 'Start_Date' and 'Current_Date' are the names of the two dates in the palette of the hierarchy. (the two Date/time field)

    * Current date is using the object > value > execution property > current Date/time

    I need a text or number field showing the difference in days. (Difference_in_Days)

    I noticed the following code is pretty standard among other responses:

    var

    Start_date = new Date (Start_Date);

    var

    Current_Date = new Date (Current_Date);

    var

    nAgeMilliseconds = Current_Date.getTime) - Start_date.getTime ();

    var

    nMilliSecondsPerYear = 365 * 24 * 60 * 60 * 1000 ;

    I know there is lack of code and code above are may not be not correct.

    Please notify.

    OK, that's because of the way that javascript and works of the calculate event.  The field will be filled with whatever the script resolves at the end of execution. Technically, your script does not have a value because the last thing you do is an assignment to a variable.  Change the last line as follows:

    Math.ABS ((firstDate.getTime)

    ((- secondDate.getTime (()) / (oneDay));

    (eliminate the variable assignment) and get rid of the app.alert.  Your script will "return" (have) regardless of the value of calculation from the East and which will be stored in the field.

  • Why machine did transfer spontaneously inbox the last 15 days in a folder named Archive / 2015?

    I got lucky that I could find where the machine had hidden messages the last 15 days.
    Am I punished for having too many messages in the box at, or what?

    Hello, you're posting in the firefox support forum - firefox is a browser and does not handle your emails. in case you use thunderbird as a mail client and you have a question about this, please say so, then we will go to your question in the queue of thunderbird.
    If you access your email via webmail, please contact your e-mail provider to help you...

    Problems with email and how to find help

  • For the last 2 days everytime I open to MY MSN, it opens in safe mode. I deleted cookies and the history of FF. all other sites open OK. Vista, 64-bit operating system.

    Vista 64 bit OS

    Thanks for the replies, the problem was on the Microsoft site itself and internal glitch for the last 2 days on the garbled causing MY MSN page without graphics and text.

  • the last two days, I get an error message and Firefox does not open. I'm on 9.0

    The last two days, Firefox will not load. I get an error screen. I'm on 9.0

    Thanks for the help. All is well in Tennessee!

    Gary

  • I have the time to default iPhone 4 iOS 7.1.2 iPhone App not updated since the last 3 days and also checked all the settings for location and also set as new iPhone always present problem... Please try to fix... Thanx

    I have the time to default iPhone 4 iOS 7.1.2 iPhone App not updated since the last 3 days and also checked all the settings for location and also set as new iPhone always present problem... Please try to fix... Thanx

    Turn off your device and turn it on again. If this does not help, sign out of your account and reconnect.

    In addition, you can try to reset your settings.

    • Press and hold the sleep/wake button
    • Press and hold the Home button
    • Press and hold both buttons until the display turns off and on again with the Apple logo on the subject.

    Alternatively, you can go to settings - general - reset - Reset all settings

  • 16 June updated blown all my documents for the last 10 days. Any solution?

    Documents for the last 10 days, all my email settings, all memory of recent activity disappeared.

    Hello Craig,.

    Let's see if the files are actually missing or if they are hidden:

    http://answers.Microsoft.com/en-us/Windows/Forum/Windows_7-files/Unhide-files-and-folders/ca46d3ba-1b51-E011-8dfc-68b599b31bf5

    Best regards

    Matthew_Ha

  • In the last 4 days, I was not able to respond to emails or send emails on my Hotmail account again.

    original title: error in hotmail

    In the last 4 days, I was not able to respond to emails or send emails on my hotmail account again. Please can someone tell how can I solve this problem?

    You will find support for Windows Live Hotmail (webmail) in these forums: http://windowslivehelp.com/forums.aspx?productid=1

    PS: You'll quickly see that you're not alone...

  • I have a HP IQ504. After some difficulties, IE9 has been installed. I get now update KB2797052 to install several times. 18 times in the last seven days.

    I'm working on a HP IQ504. After some difficulties, IE9 has been installed. I get now update KB2797052 to install several times. 18 times in the last seven days. How can I stop this update to do this? Thank you for your help

    Hi Lenny,

    Were there any changes (hardware or software) to the computer before the show?

    Click on the link below and see if it helps.

    Windows Update or Microsoft Update repeatedly offers the same update

    Note: Check the title that indicates How to solve the problem if the update has been installed

    Note: the Microsoft Safety Scanner expires 10 days after being downloaded. To restart a scan with the latest definitions of anti-malware, download and run the Microsoft Safety Scanner again.

    The Microsoft Safety Scanner is not a replacement for the use of antivirus software that offers continuous protection.

    Hope this information helps.

  • KB2538242 installation every day for the last 4 days(14-17) is this normal?

    Hello

    I was wondering why I have this KB253842 install all update for 4 days last days(14-17) is this normal?

    Just install again and now it seems he still wants me to do again... I saw the story updated and its success since the last 4 days.

    Is this normal?

    Thank you very much... Toni1010

    TONI1010,

    Troubleshooting Windows Update or Microsoft Update when you are repeatedly offered an update

    http://support.Microsoft.com/kb/910339>

    This article also describes how to do to solve the problem when the Automatic Updates downloads and installs the update even repeatedly.

    How to hide or show an update of Windows Vista

    http://www.Vistax64.com/tutorials/72491-Windows-Update.html>

    06/18 / 1112:22: 00 am

  • Why I have not received e-mails from the last 2 days?

    It seems that my account has been hacked. All my contacts were deleted and some of my emails from my inbox sent have also been removed. Quite simply, I can't receive emails. I tried to use my son's account to see if there is no message, but nothing whatsoever, just, I don't get the emails. What can I do to start getting emails again and maybe even get all my contacts back?

    Send you an email and see if you receive?  If this isn't the case, then there are probably a problem with your account.   If you get it, you may have no emails in the last 2 days (or if you are unsure that you did, just on).  If you use an e-mail program, go to the place on your online account and see if the emails are there - then the problem is that they are not transmitted for some reason any (it could be your e-mail program or it could be the provider - difficult to say at this stage).

    You need to discuss with your email provider (one that provides you with e-mail service - perhaps your ISP, but maybe someone else entirely).  They are the ones who can access these things on your account and understand what is the problem (or help you to fix your computer's settings so that you get emails again).

    I hope this helps.

    Good luck!

    Lorien - MCSA/MCSE/network + / has + - if this post solves your problem, please click the 'Mark as answer' or 'Useful' button at the top of this message. Marking a post as answer, or relatively useful, you help others find the answer more quickly.

Maybe you are looking for