To find the third Saturday of a month

Hi all

Y at - it a simple way to find the third Saturday of each month
other than two queries below.

< CODE >

-The first code (No nested query)
SELECT MAX (DECODE (LENGTH (TO_CHAR (LEVEL)), 1))
, TO_DATE (TO_CHAR (SYSDATE, 'YYYYMM') |) '0' || TO_CHAR (LEVEL), 'YYYYMMDD')
, TO_DATE (TO_CHAR (SYSDATE, 'YYYYMM') |) TO_CHAR (LEVEL), 'YYYYMMDD'))) THIRD_SAT
OF THE DOUBLE
WHERE DECODE (LENGTH (TO_CHAR (LEVEL)), 1).
, TO_CHAR (TO_DATE (TO_CHAR (SYSDATE, 'YYYYMM') |)) '0' || TO_CHAR (LEVEL), 'YYYYMMDD'), "DY")
, TO_CHAR (TO_DATE (TO_CHAR (SYSDATE, 'YYYYMM') |)) TO_CHAR (LEVEL), 'YYYYMMDD'), "DY")
) = 'SAT '.
CONNECT BY LEVEL < 22


--deuxieme code (a nested query)
MAX SELECT THIRD_SAT (ALL_DATES)
OF (MAX SELECTION (DECODE (LENGTH (TO_CHAR (LEVEL)), 1)))
, TO_DATE (TO_CHAR (SYSDATE, 'YYYYMM') |) '0' || TO_CHAR (LEVEL), 'YYYYMMDD')
, TO_DATE (TO_CHAR (SYSDATE, 'YYYYMM') |) TO_CHAR (LEVEL), 'YYYYMMDD'))) ALL_DATES
OF THE DOUBLE
CONNECT BY LEVEL < 22
)
WHERE TO_CHAR (ALL_DATES, 'DY') = 'SAT '.
< code >


Thank you and best regards,
CDPRASAD

Hello

Tubby wrote:

ME_XE?select next_day(trunc(sysdate, 'MM'), 'SATURDAY') + 14 from dual;

NEXT_DAY(TRUNC(SYSDA
--------------------
21-AUG-2010 00 00:00

1 row selected.

Elapsed: 00:00:00.00

Be careful! If the month happens to start Saturday, which returns the 4th Saturday, not the 3rd:

select  next_day ( trunc ( DATE '2010-05-15'
                , 'MM'
                )
          , 'SATURDAY'
          ) + 14
from      dual;

NEXT_DAY(
---------
22-MAY-10

That's because NEXT_DAY always returns a DATE after (not the same as) its 1st argument.
Do this instead:

select  next_day ( trunc ( DATE '2010-05-15'
                , 'MM'
                ) + 13
          , 'SATURDAY'
          )           AS third_sat
from      dual;

THIRD_SAT
---------
15-MAY-10

or, if you need something that is independent of the NLS:

select  next_day ( trunc ( SYSDATE
                , 'MM'
                ) + 13
          , TO_CHAR ( DATE '2010-07-31'     -- You can use any Saturday here
                 , 'Day'
                 )
          )           AS third_sat
from      dual;

THIRD_SAT
---------
21-AUG-10

Tags: Database

Similar Questions

  • How to find the first Sunday and the second Saturday of each month

    Hi all

    How to find the first Sunday and the second Saturday of each month

    Thank you

    Oracle Database 11 g Enterprise Edition Release 11.1.0.7.0 - 64 bit Production

    994122 wrote:

    Hello

    I need to pass the months parameter how to do this? like Jan, Feb etc... (one of those)

    Do you have a procedure?

    Should you output only for the months you passed in the parameter?

    The easiest way is to set the parameter as date. When you go such as p_date as DATE ' 2014-10-01', then you can

    PROCEDURE two_dates)

    p_date IN DATE

    p_first_sunday DATE

    p_second_saturday DATE

    )

    IS

    BEGIN

    p_first_sunday: = NEXT_DAY (TRUNC (p_date, 'MM') - 1, TO_CHAR (DATE ' 2014-10-12', 'DAY'));

    p_second_saturday: = NEXT_DAY (TRUNC (p_date, 'MM') - 1, TO_CHAR (DATE ' 2014-10-11', 'DAY')) + 7;

    END two_dates;

    Or you describe what you need.

  • Find "the third Friday of the month.

    I try to use OPA to generate a set of dates based on a number of different criteria, such as the first of each month, once a fortnight and various others. I'm fighting with that is, as the title suggests. Is it possible under rules for a set of date such as results variables, for example, will be the third Friday of each month?

    To be clear, if I enter a start date of July 19, 2011 and I put criteria like the last day of the month, I should be back July 31, 2011, August 31, 2011, September 30, 2011 and so on. (I realized that in a roundabout way, using the functions ExtractMonth, ExtractYear and MakeDate.)

    If I go into 19 July 2011, and the criterion is the second Tuesday of each month, I want to on 9 August 2011, September 13, 2011, October 11, 2011. Is there a way that someone can think that this could be done? Without using masses and masses of tables Excel days and dates (which makes the project too large to function properly) I can't find a solution, so any help would be welcome. Thank you.

    You can use the functions NextDayOfTheWeek (to get the first Friday) with AddWeeks (to get the third Friday, based on the knowledge the first Friday).

    That would give you a single output date based on a single date of entry. If you wanted a timeline of dates (i.e. a temporal attribute), then you should look at using some functions of temporal reasoning as well.

  • How to find the third element table pl/sql ina

    Hello friends,

    I have a pl/sql table of NUMERIC type, where am store all salaries of employees.

    I want to find the third bigger payday by browsing through the pl/sql table.

    Pls advice.

    Thank you/kumar
    DECLARE
        TYPE max_earnings_type IS TABLE OF NUMBER;
        TYPE max_earnings_sorted_type IS TABLE OF NUMBER
          INDEX BY BINARY_INTEGER;
        max_earnings_tab        max_earnings_type;
        max_earnings_tab_sorted max_earnings_sorted_type;
        m number;
    BEGIN
        SELECT  sal + comm
          BULK COLLECT
          INTO  max_earnings_tab
          FROM  emp;
        FOR v_i in 1..max_earnings_tab.count LOOP
          IF max_earnings_tab(v_i) IS NOT NULL
            THEN
              max_earnings_tab_sorted(max_earnings_tab(v_i)) := 1;
          END IF;
        END LOOP;
        m := max_earnings_tab_sorted.last;
        DBMS_OUTPUT.PUT_LINE('MAX value in PL/SQL table is ' || nvl(to_char(m),'NULL'));
        m := max_earnings_tab_sorted.prior(m);
        DBMS_OUTPUT.PUT_LINE('Second MAX value in PL/SQL table is ' || nvl(to_char(m),'NULL'));
        m := max_earnings_tab_sorted.prior(m);
        DBMS_OUTPUT.PUT_LINE('Third MAX value in PL/SQL table is ' || nvl(to_char(m),'NULL'));
    END;
    /
    MAX value in PL/SQL table is 2650
    Second MAX value in PL/SQL table is 1900
    Third MAX value in PL/SQL table is 1750
    
    PL/SQL procedure successfully completed.
    
    SQL> 
    

    SY.

  • I can't find the Firefox I bought several months ago. Are now all Firefox for Windows for free?

    I bought Firefox several months ago. I need to reinstall the version of Firefox, but I am unable to find the paid version of Firefox. I wonder if there is still a paid version of this product or not. Also, I created an account when I bought this article several months ago. I just need to figure out if there is a paid version of this product stll and if there is, how to find it.

    You must still download and install Firefox from the official Mozilla servers to avoid unwanted extras like malware.

    You can find the full version of the current Firefox version current (39.0) in all languages and all systems operating here:

  • Find the 2nd Sunday of each month in a report

    Hello

    I have the data of EMP_Name and Join_Date. I have to build a dashboard report where

    1. In the dashboard, there is a command prompt. If I select a year and a month then, the report is expected to show that the data of the respective month.
    2. This report will show the employees who joined the company only after the 2nd Sunday of each month until the end of the month.

    Inputs/suggestions, how to build it?

    Thanks in advance.

    You have a question, Yes... a SQL query... OBIEE do not mean SQL but LSQL, your query will be not really usable like this...

    You're right, it seems that when the first day of the month is a Saturday he jump 1 week...

    The correct formula for the 3rd Friday is:

    TIMESTAMPADD (SQL_TSI_DAY, (14 + 6-CASE WHEN DAYOFWEEK (TIMESTAMPADD (SQL_TSI_DAY, 1-DAYOFMONTH (CURRENT_DATE), CURRENT_DATE)) = 7 THEN 0 END ELSE DAYOFWEEK (TIMESTAMPADD (SQL_TSI_DAY, 1-DAYOFMONTH (CURRENT_DATE), CURRENT_DATE))), TIMESTAMPADD (SQL_TSI_DAY, 1-DAYOFMONTH (CURRENT_DATE), CURRENT_DATE))

    If instead of CURRENT_DATE you want to use your own column date just to replace in the formula and it works.

  • Is it possible to find the history of navigation 18 months ago?

    I need to find a site that I visited about 18 months ago. Is this information available?

    No, unless you see this story in the history Manager or have a backup of the places.sqlite file that you can use in a profile separated to prevent dataloss bookmarks.

    You can try to check for previous versions of the file places.sqlite.

    If you need to use an old copy of the places.sqlite and then create a new profile to extract this older file.
    See "create a profile":

    If the new profile works then you can transfer files from a profile already used in the new profile, but be careful not to copy files corrupted to avoid transporting more problems.

  • Nomination for the third Wednesday of each month

    How can I set up my monthly calendar to an event that occurs every third Wednesday of the month?  Thank you.

    Hello

    • You use windows calendar or any other program?

    If sa is the Windows Calendar, then it is not possible to do.

    http://Windows.Microsoft.com/en-us/Windows-Vista/customize-Windows-Calendar

    Diana

    Microsoft Answers Support Engineer

  • Function to find the name of the nth month [V 10 g]

    Hi Experts,

    Please, help me find the name of Nth last month [months].

    Simply use a variable?

    SQL > n number of var
    SQL > exec: n: = 3

    PL/SQL procedure successfully completed.

    SQL > select to_char (add_months (sysdate,: n), 'Month') twice;

    TO_CHAR (ADD_MONTHS (SYSDATE,: N), 'MOUNT)
    ------------------------------------
    December

    1 selected line.

    SQL > exec: n: = - 1

    PL/SQL procedure successfully completed.

    SQL > select to_char (add_months (sysdate,: n), 'Month') twice;

    TO_CHAR (ADD_MONTHS (SYSDATE,: N), 'MOUNT)
    ------------------------------------
    August

    1 selected line.

    SQL > exec: n: = 1658

    PL/SQL procedure successfully completed.

    SQL > select to_char (add_months (sysdate,: n), 'Month') twice;

    TO_CHAR (ADD_MONTHS (SYSDATE,: N), 'MOUNT)
    ------------------------------------
    November

    1 selected line.

  • I need an event to repeat the 1st Thursday of each month; the only option I have is every 8th 6 or each day.

    I wish I had a repetitive on the first event and the third Thursday of each month. I can't make it a monthly event repeated the same day of the week.

    Also, I get an overlay on my Yahoo screen that says I must be disconnected or closed another page and I need to connect when I did this. Is this a problem of Yahoo?

    For your repeat again, I guess that's your Yahoo calendar? This isn't a matter of Firefox, I suggest you try to communicate with yahoo.

    For the other questions, try the following:
    Upgrade to Firefox 15. Then, Firefox Refresh - reset the parameters and modules

  • Find the first day of the third quarter of next year

    Hello

    I'm writing a sql to find "the first day of the third quarter of the year (from the current year) next»

    I am able to get the first and the last day of the current quarter:

    Select trunc (sysdate, 'Q'), trunc (add_months (sysdate, + 3), 'Q')-1 double

    But, how to find the first day of the third quarter of the year next (from the current year) based on any date entry (i.e. sysdate)

    for example if my entry date = 12/01/2001 should be released 07/01/2015

    If my entry date = 07/04/2005 should be released 07/01/2015

    If my entry date = 20/02/2013 should be released 07/01/2015

    ... etc.

    Thanks in advance

    Hello

    The 1st day of the 3rd quarter of next year is:

    ADD_MONTHS (TRUNC (SYSDATE, 'YEAR')

    18 = 12 + 6

    )

    TRUNC (SYSDATE, 'YEAR') is the 1st day of the 1st quarter of this year

    The first day of the new year is 12 months after that, and the first day of quarter 3 is another 6 months after that.

    user634169 wrote:

    ... But, how to find the first day of the third quarter of the year next (from the current year) based on any date entry (i.e. sysdate)

    for example if my entry date = 12/01/2001 should be released 07/01/2015

    If my entry date = 07/04/2005 should be released 07/01/2015

    If my entry date = 20/02/2013 should be released 07/01/2015

    ... etc.

    Thanks in advance

    You did some errors above?

    If the effective date in 2001, why is the output in 2015, not 2002?

    If the output is based only on the date of the day (currently in 2014), why even mention a start date?

  • How to find the serial number of the processor in the MacBook pro s serial number? I have a dead MacBook that was given for service to a third party. I doubt that they have replaced the original parts. Help, please. Thank you

    How to find the serial number of the processor in the MacBook pro s serial number? I have a dead MacBook that was given for service to a third party. I doubt that they have replaced the original parts. Help, please. Thank you

    As far as I KNOW, the serial number of the MacBook does not have the serial number of the processor.

  • OBIEE 11 g: how to find the 2nd Friday of the month

    Hello

    How to find the 2nd Friday of the month using the current date in obiee 11g.

    Thanks in advance.

    Kind regards

    MIT.

    Hey MIT,

    You can try with something like this:

    TIMESTAMPADD (SQL_TSI_DAY, TIMESTAMPADD (7 + 6-DAYOFWEEK (TIMESTAMPADD (SQL_TSI_DAY, 1-DAYOFMONTH (CURRENT_DATE), CURRENT_DATE))), (SQL_TSI_DAY, 1-DAYOFMONTH (CURRENT_DATE), CURRENT_DATE))

    It can still be improved to probably avoid transformations 1-2, but at least he does.

    You will need to check what return DAYOFWEEK in your environment for Friday (in mine Friday = 6) as if she does not return to Friday 6, you will need to adjust the formula.

    The idea is to find what day is the first day of the month, since then visit the first Friday (or just stay there if the first day is a Friday). This is done by the DAYOFWEEK 6 (first day of the month).

    And now, you just add more 7 days, so that's why there is a 7 + 6 - DAYOFWEEK (first day of the month) to make it easier to read and understand (instead of 13-...).

  • How to find the first day of the month following two years one year from now?

    Hello

    I need to find the first day of the month following two years ago, based on the current date.

    For example: If today is the 31/08/2015 so I need to find the date range between 31/08/2015 and on 09/01/2013. How can I write an SQL which allows to automate this calculation instead of hard-coding the values. Please do help me out with this so that I can build the SQL that can produce the desired result.

    Thank you

    Dhilip

    find the start of the month - 2 years in advance, early - 2 years + 1 months in advance and go back 1

    Select trunc (add_months(sysdate,24), 'MM'), trunc (add_months(sysdate,25), 'MM') - 1 double;

  • Lightroom works only with reduced funktionality. Develop module is not available.  Adobe can not find the license associated with my Adobe why identification code? Every month I pay an amount for PS and LR...

    After the upgrade to Windows 10 Lightroom works only with reduced funktionality. Develop module is not available.  Adobe can not find the license associated with my Adobe why identification code? I bought the license more than 1 year ago. Every month I pay an amount for PS and LR, and for the past 4 months I can't work. Russian support team cannot solve this problem and sent me here.

    Thank you! I reset my password, the problem was in it.

Maybe you are looking for

  • iTunes unknown error 11503

    I have a Macbook Pro 2012 (not the retina), El Capitan running.  Recently updated iTunes, running 12.4.0.199 Errors access iTunes store now & same account access.  Whenever I have access to my account and try to download the downloads available, as a

  • I can't download a PDF file from the web in my downloads folder

    Since I've done the new update on firefox (8-14?) I can't download a PDF of a website in my downloads folder. When I choose to display a pdf file in a window, I get a blank window with the urlxxxx. PDF in the top... but a window empty. It is a change

  • Smartwizard discovered on machine with two IP addresses.

    Scenario:Two isolated networks, with a Win 2012 VM Server that is connected to both.There is no routing between two networks. 6 switches from Netgear, 5 including SmartControl Centre worked almost without problems for this virtual machine. (would pre

  • Time Machine replacement drive but can not see the old backups

    Race X Server on 10.11.2 with 5.0.15 My Time Machine hard disk became full and I replaced it with a new, larger, in the car. I copied everything (using the Finder) from the old to the new drive and set it as the destination of Time Machine for a coup

  • I can't use my disk clean up windows responding

    Original title: I can't use my cleaning disc It won't let me choose a player, it says that it does not. When I go ahead and press ok, it says windows is not responding.