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<=>

Tags: Oracle Development

Similar Questions

  • 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 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 get the last day of the year

    Hi all

    Thanks in advance...

    How do I get the last day of the year that I'm passing date at run time.

    I can manage to get the first day of the year by
    SELECT TRUNC(SYSDATE,'YEAR') AS FDAY_YEAR
    of the double

    Thanks in advance

    Concerning
    Sachin
      1*  select ADD_MONTHS(trunc(sysdate,'yyyy'),12)-1 dd from dual
    SQL> /
    
    DD
    -----------
    31-DEC-2010
    
  • 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");

  • How to get the same day of a month each year in the DB (update a flag)

    Hello

    I'm trying to make a update for a table of flag request in our database that contains the dates and the Pavilion columns. Currently the system have dates for the next ten years. The flags are updated with the values 0 or 1, if a particular date falls under the criteria required.

    I need to update the column flag for the same day of the month of each year. for example, 2nd Sunday of October. The value must be updated in all the years in the table. Currently I use the following query to update of the current year.

    UPDATE FILTERCALENDAR SET YEAR_WINDOW = 1 WHERE c_date = NEXT_DAY (TO_DATE('OCT-2013','MON-YYYY'), 'SUNDAY') + (2-1) * 7;

    and for the next year as

    UPDATE FILTERCALENDAR SET YEAR_WINDOW = 1 WHERE c_date = add_months (NEXT_DAY (TO_DATE('OCT-2013','MON-YYYY'), 'SUNDAY') + (2-1) * 7, + 12)-1;

    This isn't a great way to do it because he does not take care of leap years, and it does not scan and update values across the table for all the years correctly.

    Can someone help me fix this please.

    Welcome to the forum!

    Whenever you provide post your Oracle version 4-digit (result of SELECT * FROM V$ VERSION)
    >
    and for the next year as

    UPDATE FILTERCALENDAR SET YEAR_WINDOW = 1 WHERE c_date = add_months (NEXT_DAY (TO_DATE('OCT-2013','MON-YYYY'), 'SUNDAY') + (2-1) * 7, + 12)-1;
    >
    Why do you use "2013" in the TO_DATE for the year next rather than use simply '2014 '?

    You said it works
    >
    UPDATE FILTERCALENDAR SET YEAR_WINDOW = 1 WHERE c_date = NEXT_DAY (TO_DATE('OCT-2013','MON-YYYY'), 'SUNDAY') + (2-1) * 7;
    >
    Just interview the years from your table (list of the separate years) and use the query above on them.

    SELECT DISTINCT TO_CHAR(c_date, 'yyyy') FROM FILTERCALENDAR
    

    Or use this predicate

    WHERE c_date = next_day(last_day(add_months (c_date, -1)), 'SUNDAY') + 7
       AND TO_CHAR(c_date, 'mm') = '10'
    

    1 TO_CHAR ensures that the line has a month to October.
    2 ADD_MONTHS goes to Sept. 1.
    3 LAST_DAY going until the last day of September.
    4 NEXT_DAY goes to the first Sunday in October
    5 + 7 is going to the second Sunday in October

  • 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 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

  • 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}))))

  • Get the last day of the month

    Hello

    How can I get the (day number of the) last day of a given month and year?

    So, if

    year 2015 = and month = 1, the output should be 31

    year = 2012 and month = 2 while production is expected to be 29

    year 2013 = and month = 2 while production is expected to be 28

    etc.

    Y at - it no OBIEE to achieve? If not, then a command SQL Oracle is very good too (I prefer OBIEE however)

    Thanks in advance,

    Erik

    You start from the first day of the month, you add 1 month [TIMESTAMPADD (SQL_TSI_MONTH, 1, 'your date')], you must subtract 1 day [TIMESTAMPADD (SQL_TSI_DAY,-1, 'your date')] and use the DAYOFMONTH function to get the number of the last day of the month [DAYOFMONTH ('your ' date')].

    All these calls nesting together and you're there.

  • How to get the last message received in the Inbox?

    Currently I am using the following code to the list of messages in the Inbox.

    Folder[] folders = store.list(Folder.INBOX);Folder inbox = folders[0];Message[] msgs = inbox.getMessages();
    

    But, how could I do the last message that was received in my inbox at the moment?

    I have a lot of unread messages in my Inbox and I can even receive the same message from sender twice at the same time, but I need access to the last message you received.

    Thank you

    As I have a implements FolderListener, I need to get the last message of FolderEvent object. But, I tried to access the last Inbox message, which will not always be there!

    Thanks Deepesh

  • 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 first day of the week on the calendar?

    Hello

    I'm storing calendar weeks in my database. for example 30/2013.

    How can I get the first day of this week (Monday)? in this case, it is 22.07.2013

    THX

    Anja

    with your_table as)
    Select 30-2013' double your_column
    )

    Select
    trunc)
    TO_DATE ("0101"
    || (substr (your_column,-4), 'MMDDYYYY'), 'IW')
    + to_number (substr (your_column, 1, 2)) * 7-7
    start_of_week
    from your_table

    START_OF_WEEK
    22/07/2013

    Post edited by: chris227
    Corrected example

  • How to get the last parameter of exprision regular

    Hi all!
    I need to extract the last date in the string.
    Here my code
     Pattern pattern = Pattern.compile("(19|20)\\d\\d([- \\\\/.](0[1-9]|1[012])[- \\\\/.](0[1-9]|[12][0-9]|3[01]))?");
    Matcher matcher = pattern.matcher(text);
    
    while(matcher.find()) {
    
             
    System.out.println(matcher.group());
    How can I get the last date

    Example->

    Hello all the date is 2010-12-12 the date is 2010-10-10
    and I want to get-> 2010-10-10

    Thank you!

    Just assign the value of the find to a variable declared outside the loop. The variable will hold the last game when you exit the loop.

    Kaj

  • How to get the last DML statement in each block

    Hello

    How can I get the latest DML statements in each block.
    As SYSTEM. LAST_QUERY returns the last select statement, I need to get the last Insert/Update/Delete statement
    in each block.

    Thanks in advance

    Rizly

    Rizly,

    You can use the GET_BLOCK_PROPERTY to get the last query executed on this block.

         MESSAGE(GET_BLOCK_PROPERTY('', LAST_QUERY));
    

    Kind regards

    Manu.

    If this answer is useful or appropriate, please mark. Thank you.

Maybe you are looking for

  • Shortcuts with single letter keys can produce unexpected results. Why no function keys?

    Sometimes I start typing a reply, or by entering a key word to search without having to pay a lot of attention when the window focus is. If it's on the messaged pane, a few keystrokes can correspond to a single letter shortcuts, mess up the Inbox wit

  • Is it possible to remove a file from your time Machine?

    Is it possible to remove a file (s) from your time Machine?  When I tried, I got a pop up says that backs up the items cannot be changed. How do you get the room on your Time Machine disk?

  • iBooks do not sync via iTunes or iCloud PDF files

    the last time I opened iBooks on my macbook, asked if I wanted to synchronize via iCloud. Works well with the calendars on my 3 devices (iPhone, iPad, macbook) so I said yes. But none of my new PDF in iBooks on macbook appeared on my iPhone. Open iTu

  • How to search a folder of documents Word for Word?

    Hello. I have a folder of Word documents with random names, a recent recovery disk. I have a few documents I want to filter based on words that are in their midst. How can I do this on a Mac? I tried to use EasyFind as posters suggested, and while it

  • Film loop with automator doesn´t stay full screen.

    I m doing a video art installation with a 30-minute film that should loop several times. Simply put, I want the film to go as soon as the computer is started. Do that I ve done a soft in automator that I use as a start object. The app tells quicktime