How to get the last day of the weekend rather than a month

Hi all

Is the request appropriate and preferable to use to get the last business day of the month below?

SELECT to_date('13.08.2014','dd.mm.yyyy') + MAX(RNUM) LastDay(nonweekend)
   FROM   (SELECT ROWNUM RNUM
          FROM   ALL_OBJECTS where rownum <=31)
  WHERE   ROWNUM <= 31 ANd
     TO_CHAR(to_date('13.08.2014','dd.mm.yyyy') + RNUM, 'DY','NLS_DATE_LANGUAGE=ENGLISH' ) NOT IN ('SAT' , 'SUN')
     and to_date('13.08.2014','dd.mm.yyyy') + RNUM <= last_day(to_date('13.08.2014','dd.mm.yyyy'))

I have to use this motion for production.

East - recommended to use?

You can change your query this way:

WITH t AS (SELECT trunc (to_date ('& calc_date', 'dd.mm.yyyy'), 'mm') + level - 1 calc_date)

OF THE DOUBLE

CONNECT BY LEVEL<= last_day(to_date('&calc_date',="" 'dd.mm.yyyy'))="" -="" trunc(to_date('&calc_date',="" 'dd.mm.yyyy'),="" 'mm')="" +="">

)

Select max (calc_date)

t

where to_char (calc_date, 'DY', 'NLS_DATE_LANGUAGE = ENGLISH') NOT IN ("SAT", "Sun");

Tags: Database

Similar Questions

  • How to get the second Monday of each month in a given date range?

    In Oracle forms, how to get the second Monday of each month in a given date range?

    I tried below using the query WITH the Clause, but it seems that WITH Clause does not work in Oracle forms. So is there another way to do this in Oracle forms?

    WITH month_range AS

    (

    SELECT TO_DATE ('Dec 2013', 'Mon YYYY') AS first_month

    , TO_DATE ('Mar 2014', 'Mon YYYY') AS last_month

    OF the double

    )

    SELECT NEXT_DAY (6 + ADD_MONTHS (first_month

    , LEVEL - 1

    )

    , 'MONDAY '.

    ) AS second_monday

    OF month_range

    CONNECTION OF LEVEL < = 1 + MONTHS_BETWEEN (last_month, first_month)

    ;

    Thanks in advance.

    Good fishing, when the first day of the month is Thursday... So I changed the query accordingly... Try the below

    SELECT CASE WHEN TO_CHAR (ADD_MONTHS (TRUNC(startdate,'MM'),(LEVEL-1)), 'DY') = 'game '.

    THEN NEXT_DAY (ADD_MONTHS (TRUNC(startdate,'MM'),(LEVEL-1)), 'THU')

    Of OTHER NEXT_DAY (ADD_MONTHS (TRUNC(startdate,'MM'),(LEVEL-1)), 'Game') + 7

    END AS second_day

    FROM (SELECT SYSDATE startdate,

    SYSDATE + 300 enddate

    THE DOUBLE)

    CONNECT BY LEVEL<=>

  • How to change the graphics rather than the windows screen resolution

    Hello

    Intel graphics card;
    In response to the question of size screen. How him alter the graphics rather than windows.

    Granniebiker

    Hello

    I m not very well what you want to do?  :|
    You want to change the resolution of your laptop screen?

    I assume you have an XP operating system.
    If you can make them using two different ways.

    (1) go to-> graphic display Manager Control Panel Intel-> in one available tabs, you can change the display settings

    (2) using a second way to make a right click on the desktop-> properties-> settings tab
    There is also a setting to change the display resolution.

    Good bye

  • That's why when I want to sign into xbox live on my console, I get the join rather than the sign in guest

    Original title: sign in error xbox

    That's why when I want to sign into xbox live on my console, I get the join rather than the sign in guest?

    Hello

    The issue you have posted is related to Xbox Live, I recommend you post this question in the Xbox forum.

    http://forums.Xbox.com/xbox_forums/xbox_support/default.aspx

  • How to get sales last day of the previous month

    HELO guys

    I have a question how do I get sales date last day of the previous month where my fact table is level. in fact I tried using Ago but it seems not working. for example, if I chose December 29, 2014 so if I used the function there are then the result will display data on November 29, 2014 (not the last day of November 2014).

    Please guys if you have any solution and I really advise thanks to you.

    Not exactly under what circumstances specific as you try to reach this goal, but suppose you have a few guest dashboard where you select a day and you have a report with a measure where you want to show the sales of the last day of the previous month based on the selected date in the dash prompt.

    If you change the formula of this measure to something like:

    FILTER (with the HELP of 'Sales' (DATE = TIMESTAMPADD (SQL_TSI_DAY-1, TIMESTAMPADD (SQL_TSI_DAY, DAYOFMONTH(@{PV_DATE_SELECTED}) * (-1) + 1, @{PV_DATE_SELECTED}))))

  • How to get the desired result when subsequent month is not available

    WITH T1
         AS (SELECT 'A' COL1,
                    'B' COL2,
                    'C' COL3,
                    '01-Jan-2015' DT,
                    10 QTY
               FROM DUAL
             UNION
             SELECT 'A' COL1,
                    'B' COL2,
                    'C' COL3,
                    '01-feb-2015' DT,
                    20 QTY
               FROM DUAL
             UNION
             SELECT 'A' COL1,
                    'B' COL2,
                    'C' COL3,
                    '01-mar-2015' DT,
                    30 QTY
               FROM DUAL
             UNION
             SELECT 'A' COL1,
                    'B' COL2,
                    'C' COL3,
                    '01-may-2015' DT,
                    40 QTY
               FROM DUAL
             UNION
             SELECT 'A1' COL1,
                    'B1' COL2,
                    'C1' COL3,
                    '01-mar-2015' DT,
                    40 QTY
               FROM DUAL
             UNION
             SELECT 'A1' COL1,
                    'B1' COL2,
                    'C1' COL3,
                    '01-may-2015' DT,
                    40 QTY
               FROM DUAL)
    SELECT *
      FROM t1
    
    

    Current output:

    COL1COL2COL3DTQTY.
    ABCJanuary 1, 201510
    ABCFebruary 1, 201520
    ABC01-mar-201530
    ABC01-may-201540
    A1B1C101-mar-201540
    A1B1C101-may-201540

    Expected results

    COL1COL2COL3DTQTY.DTREQ_VAL
    ABC01/01/20151001/01/201520
    ABC01/02/20152001/02/201530
    ABC01/03/20153001/03/20150
    ABC01/05/20154001/05/20150
    A1B1C101/03/20154001/03/20150
    A1B1C101/05/20154001/05/20150

    Logic:

    If we COL1, COL2, COL3 combination for A, B, C, we have the quantity for 1 January, 1 February, 1 March, 1 may, and we don't have quantity for April 1 and June 1. I need following QUANTITY value as another column. If I use the lead, I'll get the value from May 1st to March 1st, but I want to value 0 because it is after March either.

    What I've tried so far:

    SELECT *
      FROM (WITH T1
    AS (SELECT 'A' COL1,
    'B' COL2,
    'C' COL3,
    '01-Jan-2015' DT,
    10 QTY
    FROM DUAL
    UNION
    SELECT 'A' COL1,
    'B' COL2,
    'C' COL3,
    '01-feb-2015' DT,
    20 QTY
    FROM DUAL
    UNION
    SELECT 'A' COL1,
    'B' COL2,
    'C' COL3,
    '01-mar-2015' DT,
    30 QTY
    FROM DUAL
    UNION
    SELECT 'A' COL1,
    'B' COL2,
    'C' COL3,
    '01-may-2015' DT,
    40 QTY
    FROM DUAL)
            SELECT COL1,
     COL2,
     COL3,
    TO_DATE (T1.DT) DT,
    NVL (QTY, 0) QTY,
     MONTHS.DT ALL_DATES,
     LEAD (NVL (QTY, 0), 1, 0) OVER (ORDER BY MONTHS.DT) REQ_VAL
              FROM T1,
    (    SELECT ADD_MONTHS (TO_DATE ('01-jun-2015'), LEVEL - 6) DT
    FROM DUAL
    CONNECT BY LEVEL <= 12) MONTHS
             WHERE MONTHS.DT = T1.DT(+))
    WHERE DT ISNOTNULL;
    
    
    
    
    
    

    My query works for a set of COL1, COL2, COL3, am looking how we can achieve multiple COL1, COL2, COL3 (or) otherwise better query writing.

    Thanks for your suggestions in advance.

    Thank you

    Now, to understand your condition: your additional column must indicate the amount of the next month, or zero if it is not a record for the month. How about this?

    WITH T1

    AS (SELECT 'A' COL1,)

    'B' COL2,

    COL3 'C ',.

    To_date('01-Jan-2015','dd-mon-yyyy') DT,

    QTY 10

    OF THE DOUBLE

    UNION

    SELECT 'A' COL1,

    'B' COL2,

    COL3 'C ',.

    To_date('01-Feb-2015','dd-mon-yyyy') DT,

    QTY. 20

    OF THE DOUBLE

    UNION

    SELECT 'A' COL1,

    'B' COL2,

    COL3 'C ',.

    To_date('01-Mar-2015','dd-mon-yyyy') DT,

    QTY 30

    OF THE DOUBLE

    UNION

    SELECT 'A' COL1,

    'B' COL2,

    COL3 'C ',.

    To_date('01-May-2015','dd-mon-yyyy') DT,

    QUANTITY 40

    OF THE DOUBLE

    UNION

    SELECT 'A1' COL1,

    COL2 "B1."

    COL3 "C1"

    To_date('01-Mar-2015','dd-mon-yyyy') DT,

    QUANTITY 40

    OF THE DOUBLE

    UNION

    SELECT 'A1' COL1,

    COL2 "B1."

    COL3 "C1"

    To_date('01-May-2015','dd-mon-yyyy') DT,

    QUANTITY 40

    THE DOUBLE)

    X.Col1, x.col2, x.col3, x.dt, x.qty, NVL(y.qty,0) SELECT req_val

    THE t1 x

    LEFT OUTER JOIN t1 y

    ON y.col1 = x.col1

    AND y.col2 = x.col2

    AND y.col3 = x.col3

    AND y.dt = add_months(x.dt,1)

    ORDER BY 1,2,3,4

    My query works for a DFU, am looking how we can achieve multiple UTD

    What is a DFU?

  • How to get the value less than 0 = 0

    I'm trying to get a formula to do two operations of a field given something like:

    Form1. #subform [0].yes1.qn1::calculate - (JavaScript, client)

    (p1-s1)

    Then, if the value is less than '0' the value '0 = '.

    what I have so far does not work, any help is greatly appreciated.

    If

    (this.rawValue < 0)

    this.rawValue

    = 0;

    Thank you.

    I put the following code in the event the qn4 field Calculate... FormCalc language...

    If this isn't what you're trying to do, then please explain in detail...

    If ((p4-s4) == 0) then
    $.rawValue = 0;
    on the other
    $.rawValue = (p4 - s4);
    endif

    Thank you

    Srini

  • How to get the last date of 3 days for the current month?

    Hello. Guy

    How to get the last date of 3 days for the current month?

    MY OUTPUT WOULD LOOK LIKE THIS

    JANUARY 29, 2016

    JANUARY 30, 2016

    JANUARY 31, 2016


    GUYS HELP ME / / /...

    SQL > select last_day (sysdate) - level + 1 double connect by level<= 3="" order="" by="">

    LAST_DAY)

    ---------

    29 JANUARY 16

    30 JANUARY 16

    31 JANUARY 16

  • How to get the last day of a month for every 2 months for a given period?

    Hello

    Can is it some please let me know how to get the last day, last day of the week, the weekend last day, last Monday, one month for every 2 months for a given period?

    Thanks in advance.

    Try the below

    SELECT LAST_DAY (ADD_MONTHS (TRUNC(startdate,'MM'), ((LEVEL*2)-2))) lastday.

    BOX WHEN TO_CHAR (LAST_DAY (ADD_MONTHS (TRUNC(startdate,'MM'), ((LEVEL*2)-2))), 'DY') = 'SAT '.

    SO LAST_DAY (ADD_MONTHS (TRUNC(startdate,'MM'), ((LEVEL*2)-2)))-1

    WHERE TO_CHAR (LAST_DAY (ADD_MONTHS (TRUNC(startdate,'MM'), ((LEVEL*2)-2))), 'DY') = 'Sun '.

    THEN LAST_DAY (ADD_MONTHS (TRUNC(startdate,'MM'), ((LEVEL*2)-2)))-2

    Of OTHER LAST_DAY (ADD_MONTHS (TRUNC(startdate,'MM'), ((LEVEL*2)-2)))

    END as lastweekday,

    BOX WHEN TO_CHAR (LAST_DAY (ADD_MONTHS (TRUNC(startdate,'MM'), ((LEVEL*2)-2))), 'DY') IN ('Sam', 'SUN')

    THEN LAST_DAY (ADD_MONTHS (TRUNC(startdate,'MM'), ((LEVEL*2)-2)))

    Of OTHER LAST_DAY (ADD_MONTHS (TRUNC(startdate,'MM'), ((LEVEL*2)-2)))

    -(TO_NUMBER (TO_CHAR (LAST_DAY (ADD_MONTHS (TRUNC(startdate,'MM'), ((LEVEL*2)-2))),' from)) - 1).

    END as lastweekendday,

    BOX WHEN TO_CHAR (LAST_DAY (ADD_MONTHS (TRUNC(startdate,'MM'), ((LEVEL*2)-2))), 'DY') = 'MY

    THEN LAST_DAY (ADD_MONTHS (TRUNC(startdate,'MM'), ((LEVEL*2)-2)))

    Of OTHER NEXT_DAY (LAST_DAY (ADD_MONTHS (TRUNC(startdate,'MM'), ((LEVEL*2)-2))), "LUN")-7

    END AS lastmonday

    FROM (SELECT SYSDATE startdate,

    SYSDATE + 300 enddate

    THE DOUBLE)

    CONNECT BY LEVEL<=>

  • How to get the last day of the week?

    HII

    I can get the week number of calendar for a given date using

    SELECT to_char (to_date('04/04/2011','MM/DD/YYYY'), 'WW') FROM dual

    can any body tell me, how to get the last day of the week?

    and the answer should be: 04/08/2011(8th april)
    Thank you
    San

    Published by: sandeep9 on April 4, 2011 03:50

    Perhaps this...

    SQL> select trunc(sysdate,'WW')+6 from dual;
    
    TRUNC(SYSDATE,'WW')+
    --------------------
    08-APR-2011 00:00:00
    
    SQL>
    
  • How to get the maximum number of days in a month?

    How to get the maximum number of days in a month?

    I use a dateField. where I can get the month. Now, I want to get the maximum number of days in a month.

    How can I get it?

    Please help me. and thanks in advance... []

    NET. RIM. Device.API.util
    Class DateTimeUtilities

    getNumberOfDaysInMonth (int month, int year)
    Returns the number of days in the specified month

    It took me like 10 seconds to find it in the API, I guess you spent more time writing the post...

  • How to get the last access to the workflow? (OM, WMS) release 11.5.9

    Hello my friends.

    I am looking for information on how to get the date of the access and the user name who did use some WFs in OM and last WMS.

    If it is through the application or running in the background via SQL for the information is not important to me.

    Could you help me with this?.

    Thank you

    the 'item_type' attribute must match the name of the WF?

    Yes (internal name. For example OEOL).

    The custom of those who will not be affected by the upgrade.

    You must run the query that I provided before to identify if the workflow is used or not.

    For the workflow of order lines, it is intended to be used as you use the order management.

    Kind regards

    Bashar

  • How to get the 'DAY' based on the territory of current account held a number between

    Hi all

    Looks like I'm at the end of my intelligence here but how to get the 'DAY' based on the territory of current account with a number between 1 and 7? Oracle has functions to extract the day of the week, but I can't find the other way around.
    SQL> select * from v$version;
    
    BANNER
    --------------------------------------------------------------------------------
    Oracle Database 11g Release 11.2.0.3.0 - 64bit Production
    PL/SQL Release 11.2.0.3.0 - Production
    CORE    11.2.0.3.0      Production
    TNS for Linux: Version 11.2.0.3.0 - Production
    NLSRTL Version 11.2.0.3.0 - Production
    
    SQL> alter session set nls_territory=AMERICA;
    
    Session altered.
    
    SQL> select to_char (sysdate, 'D') from dual;
    
    T
    -
    3
    
    SQL> alter session set nls_territory=GERMANY;
    
    Session altered.
    
    SQL> select to_char (sysdate, 'D') from dual;
    
    T
    -
    2
    I need a way to know that the number '3' on the database with NLS_TERRITORY = AMERICA means a 'Tuesday' or the number '2' on a database with NLS_TERRITORY = GERMANY means "Tuesday" as well.

    Hope I am clear enough.

    And wish you all a happy new year :)

    Kind regards
    Smail

    Use the format "IW" to get the date of Monday and the format "DAY" to get the "first day of the week. Then compare dates to see if they are identical.

    ALTER SESSION SET NLS_TERRITORY = 'AMERICA';
    
    SELECT TRUNC(SYSDATE-LEVEL, 'IW') "Monday",
    TRUNC(SYSDATE-LEVEL, 'DAY') "NLS First day of week",
    MOD(TRUNC(SYSDATE-LEVEL, 'IW') - TRUNC(SYSDATE-LEVEL, 'DAY') + 7, 7) "1 if day 1 = SUN, 0 if MON"
    FROM DUAL CONNECT BY LEVEL <= 7;
    
    Monday    NLS First day of week 1 if day 1 = SUN, 0 if MON
    --------- --------------------- --------------------------
    31-DEC-12 30-DEC-12                                      1
    24-DEC-12 30-DEC-12                                      1
    24-DEC-12 23-DEC-12                                      1
    24-DEC-12 23-DEC-12                                      1
    24-DEC-12 23-DEC-12                                      1
    24-DEC-12 23-DEC-12                                      1
    24-DEC-12 23-DEC-12                                      1
    
    alter session set nls_territory = 'FRANCE';
    
    SELECT TRUNC(SYSDATE-LEVEL, 'IW') "Monday",
    TRUNC(SYSDATE-LEVEL, 'DAY') "NLS First day of week",
    MOD(TRUNC(SYSDATE-LEVEL, 'IW') - TRUNC(SYSDATE-LEVEL, 'DAY') + 7, 7) "1 if day 1 = SUN, 0 if MON"
    FROM DUAL CONNECT BY LEVEL <= 7;
    
    Monday   NLS First day of week 1 if day 1 = SUN, 0 if MON
    -------- --------------------- --------------------------
    31/12/12 31/12/12                                       0
    24/12/12 24/12/12                                       0
    24/12/12 24/12/12                                       0
    24/12/12 24/12/12                                       0
    24/12/12 24/12/12                                       0
    24/12/12 24/12/12                                       0
    24/12/12 24/12/12                                       0
    

    Or it could be simpler:

    ALTER SESSION SET NLS_TERRITORY = 'AMERICA';
    
    WITH DATA AS (SELECT LEVEL INPUT_DAY FROM DUAL CONNECT BY LEVEL <= 7)
    SELECT INPUT_DAY,
    TO_CHAR(TRUNC(SYSDATE, 'Day')+INPUT_DAY-1, 'DAY') "Day label"
    from data;
    
    INPUT_DAY Day label
    --------- ------------------------------------
            1 SUNDAY
            2 MONDAY
            3 TUESDAY
            4 WEDNESDAY
            5 THURSDAY
            6 FRIDAY
            7 SATURDAY
    
    alter session set nls_territory = 'FRANCE';
    
    WITH DATA AS (SELECT LEVEL INPUT_DAY FROM DUAL CONNECT BY LEVEL <= 7)
    SELECT INPUT_DAY,
    TO_CHAR(TRUNC(SYSDATE, 'Day')+INPUT_DAY-1, 'DAY') "Day label"
    from data;
    
    INPUT_DAY Day label
    --------- ------------------------------------
            1 MONDAY
            2 TUESDAY
            3 WEDNESDAY
            4 THURSDAY
            5 FRIDAY
            6 SATURDAY
            7 SUNDAY
    
  • How to get the difference in dates in days

    Hi friends,

    How to get the date difference between two dates exactly

    date2-date1 days exactly... shouyld rounded to the nearest value of...

    and one entire display i mean positive integer
    Select round ((sysdate) - to_date (date_start)), date_start days of per_periods_of_service

    This gives negative also result

    Hello

    776317 wrote:
    Hi friends,

    How to get the date difference between two dates exactly

    date2-date1 days exactly... shouyld rounded to the nearest value of...

    Date1 - date2 is the exact number of days is after date2 date1. (It is as accurate as possible, given that the DATEs do not have fractions of a second).

    and one entire display i mean positive integer
    Select round ((sysdate) - to_date (date_start)), date_start days of per_periods_of_service

    You want to probably get the exact number of days first, then ROUND this number:

    SELECT  ROUND (SYSDATE - TO_DATE (date_start, ...))   AS days
    FROM    per_periods_of_service; 
    

    Always pass arguments at least 2 to TO_DATE:
    (1) the string to be converted, and
    (2) a saying string how (1) is formatted

    This gives negative also result

    Right; If date1 is before date2 then date1 - date2 returns a negative number.
    If you want to never get a negative value, use ABS (date2 - date1). If it returns 4, then you know that one of the DATEs was 4 days before the other, but you won't know who was earlier.

    I hope that answers your question.
    If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) and also publish outcomes from these data.
    Explain, using specific examples, how you get these results from these data.
    Always tell what version of Oracle you are using.

  • How to get the date in the exact day in the field when another?

    Hello

    Please help me how to get the day of the week using another date field.

    In fact, a field (week_day) has 1,2,3,4,5,6,7 here 1-, 2 - KILL like this.
    another field has the date. After this date, go to this particular week and need to pick up the date of the Etiquettemois above. It should be this week there himself.

    Thanks in advance!

    Kind regards
    Florian...

    Published by: Florian on October 29, 2010 03:07

    Maybe it's

    select trunc(date_field,'D') + week_field - 1 from table
    

Maybe you are looking for