Calculating given occurance of a given day in every month

Hi,
I'm using oracle 10.2.0.1.0 and forms 6i.
I have inputs like frequency, day and start date.
Suppose
Start Date : 12-03-2011
Day : Saturday
Frequency : 2
What i want to do is, i want to calculate 2nd occurance of saturday(2nd Saturday), in every month, starting from the given date, till the end of the year.
The given start date, is anyway the 2nd occurance of saturday in March.
So now in april -- its is 09-04-2011
May -- 14-05-2011
June -- 11-06-2011
Is there a way to calculate like this?
Please help
Thanks

Hi,
Another way is to use the NEXT_DAY function, like this:
WITH     parameters     AS
     SELECT     DATE '2011-03-12'     AS start_date
     ,     'SATURDAY'          AS week_day
     ,     2               AS week_num     -- This isn't really a frequency
     FROM     dual
,     all_dates     AS
     SELECT  start_date
     ,     NEXT_DAY ( ADD_MONTHS ( TRUNC (start_date, 'MONTH')
                          , LEVEL - 1
                          ) + (7 * week_num)
                         - 8
                 , week_day
                )     AS a_date
     FROM     parameters
     CONNECT BY     LEVEL     <= 12
SELECT       a_date
FROM       all_dates
WHERE       a_date          >= start_date
AND       TRUNC (a_date, 'YEAR') = TRUNC (start_date, 'YEAR')
ORDER BY  a_date
;If you're doing this in Oracle Forms, then you don't need a sub-query like parameters. You can pass the parameters in PL/SQL variables, and use dual as the base table in all_dates (or use a PL/SQL loop).
The calculation of a_date works like this:
First, we find the beginning of the month.
Then, we add wekk_num weeks to that. For example, if week_num=2, that will give us the beginning of the 3rd week.
We're interested in the week before that, so we subtract 7, and we also subtract another 1 because NEXT_DAY always returns a date after (not the same as) its 1st argument.
Unfortunately, NEXT_DAY is always dependent on NLS_LANGUAGE. If you specify 'Saturday', but that day is called 'Lördag' in your NLS language, you'll get an error. If that's a possibility, then you can change the first sub-query like this:
WITH     parameters     AS
     SELECT     DATE '2011-03-12'     AS start_date
     ,     TO_CHAR ( DATE '2011-04-02'     -- or any Saturday
               , 'DAY'          
               )          AS week_day
     ,     2               AS week_num
     FROM     dual
) ...Instead of April 2, 2011, you can you any Saturday you want; just be sure it's a Saturday.

Similar Messages

  • How do I set a reminder for the last day of every month

    Have I missed something? But how do you set a reminder for the last day of every month to recurr indefinatley in iOS6? Sorry if this is really simple but I just can't seem to work it out. Any help gratefully received.

    Hey Mattye88 not sure if you have seen but actully you can do this, but for some reason you have to use Siri.  If you bring up Siri and say "set a reminder ever 4 weeks from next wednesday to check the gas meter" it will set one and it will work just fine, I have reminders to water a Bonsai every three days and it works fine it just shows as custom repeat on the user interface.  Alas it seems you can not use Siri to set one for the end of the month though which is why I am in this threed.  Still hope it helps you to know how to sort this problem atleast.

  • Scheule a job that runs on first day of every month

    Hi i want to schedul a job (run a procedure ) on first day of every month . I have done something lije this
    declare
    nextdate date;
    begin
    SELECT trunc(add_months(sysdate,1),'MM') into nextdate FROM DUAL ;
    dbms_output.put_line(nextdate);
    dbms_job.submit(
    what=>'someprocedure',
    next_date=>nextdate,
    interval=>'30');
    end;
    is interval mandatory ? how can i define that interval ??

    Hi,
    You can define an interval as follows:
    SQL> alter session set nls_date_format='dd-mm-yyyy hh24:mi:ss';
    Session altered.
    SQL> select add_months(trunc(sysdate, 'mm'), 1) from dual;
    ADD_MONTHS(TRUNC(SY
    01-09-2009 00:00:00
    1 row selected.
    SQL> select add_months(trunc(sysdate, 'mm'), 1) + 7/24 from dual;
    ADD_MONTHS(TRUNC(SY
    01-09-2009 07:00:00So, if you want your job to start at 07.00 every month you submit:
    declare
    nextdate date;
    begin
    SELECT trunc(add_months(sysdate,1),'MM') into nextdate FROM DUAL ;
    dbms_output.put_line(nextdate);
    dbms_job.submit(
    what=>'begin someprocedure; end;',
    next_date=>sysdate,
    interval=>'add_months(trunc(sysdate, ''mm''), 1) + 7/24');
    end; untested
    Check the docs: http://tahiti.oracle.com
    and/or http://asktom.oracle.com
    and/or this forum as well.
    Do some searches and you'll find lots of examples.

  • Want to get the 25th day of every month Date Function

    Dear All,
    i want want to get the 25th day of every month
    like.
    select sysdate from dua.
    Regards

    i want want to get the 25th day of every month By saying 'day', do you mean days like - Sunday, Monday, etc.?
    Why I'm in doubt is 25th of every month will always be 25 like '25-Jan', '25-Feb', '25-Mar', etc...
    In case you need the other way -
    SELECT
                ADD_MONTHS (
                            TRUNC (TO_DATE (SYSDATE), 'YEAR'), LEVEL - 1
                            ) + 24,
                TO_CHAR (
                    ADD_MONTHS (
                            TRUNC (TO_DATE (SYSDATE), 'YEAR'), LEVEL - 1
                            ) + 24
                    , 'DAY')
          FROM DUAL
    CONNECT BY LEVEL <= 12;Output:
    25-Jan-2013     FRIDAY  
    25-Feb-2013     MONDAY  
    25-Mar-2013     MONDAY  
    25-Apr-2013     THURSDAY
    25-May-2013     SATURDAY
    25-Jun-2013     TUESDAY 
    25-Jul-2013     THURSDAY
    25-Aug-2013     SUNDAY  
    25-Sep-2013     WEDNESDAY
    25-Oct-2013     FRIDAY  
    25-Nov-2013     MONDAY  
    25-Dec-2013     WEDNESDAY

  • Calculated item divided by number of days in a month

    Hello.
    I'm trying to create a calculated item, that is supposed to represent a column member, divided by the number of days in a month that's selected from the dashboard prompt.
    I know that I need an SQL function to get the number of days, but I don't think that you can use SQL functions when creating calculated items.
    Is there a way to do this?

    Looks like you are thinking too much
    Use expression builder in the rpd and then just use available functions without 2nd thought.
    if helps mark

  • How to get 10th day of every month?

    Hi All,
    please find the below requirement , how to achive this?
    " Show the Actual as a bar on a monthly frequency, with Actual costs shown as they existed on the 10th business day of each month, going back six months – the Target can be shown as a line"
    Please help me out
    thanks
    Swapna

    HI ,
    implement this function in ur colum edit
    EVALUATE('TRUNC(%1,''MONTH'')+09',colmn_name)
    u wil get answer for this requirement
    regards
    srinivas

  • How to create appointment occurs last day of each month

    Hi Preston,
    I am trying to create a monthly recurring appointment occurs on last day of every month in .Net. E.g. start at May 31, 2010 end at May 31 2011 every month.
    I specified the frequency as monthly, byMonthDay[0] = (sbyte)31. But this only generates the instances on those months contain the 31th day. My question is how to also create instances on 30th day for those months don't contain the 31th day.
    Thanks,
    John

    The recurrence rule logic is patterned after the recurrence
    logic in iCalendar (http://www.ietf.org/rfc/rfc2445.txt)
    If you have questions, first look there. Then look at the
    schema itself.
    In the schema the definition of DayOfMonth will handle
    negative numbers:
    <xs:simpleType name="DayOfMonth">
    <xs:restriction base="xs:byte">
    <xs:minInclusive value="-31"/>
    <xs:maxInclusive value="31"/>
    </xs:restriction>
    </xs:simpleType>
    <xs:complexType name="DayOfMonthList">
    <xs:sequence>
    <xs:element name="day" type="tns:DayOfMonth" minOccurs="0"
    maxOccurs="unbounded"/>
    </xs:sequence>
    </xs:complexType>
    So, the last day of the month would be -1. The second
    to last day would be -2 and so on.
    >>> On Wednesday, May 26, 2010 at 11:56 AM, Johnny
    77<[email protected]> wrote:
    > Hi Preston,
    >
    > I am trying to create a monthly recurring appointment occurs on last
    > day of every month in .Net. E.g. start at May 31, 2010 end at May 31
    > 2011 every month.
    >
    > I specified the frequency as monthly, byMonthDay[0] = (sbyte)31. But
    > this only generates the instances on those months contain the 31th day.
    > My question is how to also create instances on 30th day for those months
    > don't contain the 31th day.
    >
    > Thanks,
    > John

  • Check if a license exists for at least one day in each month

    How to check if a license exists for at least one day in each month for a given period ? Example : If we have a review period from Jan 25 2009 to Aug 15 2009. How to check if there is license for at lease one day in every month.

    Hi,
    Welcome to the forum!
    (1) construct a table or result set that has one row per month in the review period. [This thread|http://forums.oracle.com/forums/thread.jspa?messageID=3651350?] has a similar problem.
    (2) outer-join your actual data to that result set
    (3) use the aggreagate COUNT (x) function (where x is some column from your table) to see if there were any matches in each month. GROUP BY months.
    For a more specific answser, ask a more specific question.
    Post a little sample data (CREATE TABLE and INSERT statements), and the results you want from that data.
    It never hurts to say what version of Oracle you're using.
    Edited by: Frank Kulash on Jul 28, 2009 1:54 PM
    Maybe something like:
    WITH  all_months  AS
         SELECT     ADD_MONTHS ( TRUNC ( &period_begin_date
                                , 'MM'
                      , LEVEL - 1
                      )         AS month_date
         FROM    dual
         CONNECT BY  LEVEL <= 1 + CEIL ( MONTHS_BETWEEN ( &period_end_date
                                                          , &period_begin_date
    SELECT       m.month_date
    ,       CASE  COUNT (l.license_date)
                WHEN  0  THEN  'Nothing this month'
                          ELSE  'Some licenses issued'
           END     AS summary_txt
    FROM            all_months     m
    LEFT OUTER JOIN     license_table     l     ON  m.month_date     = TRUNC (l.license_date, 'MM')
                                     AND l.license_date     BETWEEN  &period_begin_date
                                                AND      &period_end_date
    GROUP BY  m.month_date
    ORDER BY  m.month_date
    ;Untested

  • ICal 3.0: Last day of the month repeating event

    I am migrating back to iCal after a few years using Entourage. I am trying to set up calendar events and reminders for the last day of every month, but I can't figure out how to do it. In Entourage this was easy. Any advice? Thank you.

    I would like this to be an easy feature included in iCal as I get paid on the 16 and second to last day of the month. I want iCal to show the event in the calendar, not for me to set the event and have an alarm for 24 hours before. I tried the trick found at http://www.macworld.com/article/47872/2005/11/trickical.html but that does not work with iCal 3.0.
    Any help would be appreciated or maybe Apple adding this in the repeating section of the ical event seeing it is apart of the icalendar specification.
    tim

  • 3 Dots in Corner Of Day Box in Month View

    When in the month view of iCal several days of every month have 3 periods/dots in the upper left hand corner of the day box that can't be deleted. Ever see this and can they be erased.
    Thanks

    My problem is related, and I would like to display these. Is there an override? There seems to be at least 1/2 of each daily box empty.
    ical: show all-day events on monthly view?
    I use iCal to track rentals in a couple of vacation apartments I manage. I have separate calendars for each, and more for personal items, etc., and a typical event would cover 7 days as an all-day event. When I checkmark 4 calendars, only 3 events will show up in the monthly view, the other(s) being designated as 3 dashes instead of the info (---). Is there a way to override this so I can quickly see what is booked for an entire month? Switching back and forth to weekly view doesn't cut it, when I need to answer availability questions quickly.

  • How do I set a recurring event for the last day of the month on iphone 4s calendar?

    I want to set a recurring event for the last day of every month - regardless of the date/number of days in the month. I'd prefer not to have to use an app to do this.

    Hi,
    You can do this using the custom repeat in iCal. You'll need two events to cover the second and fourth Mondays.
    Create the event on the second Monday of the month. In Repeat select Custom... > Frequency: Monthly > On the: second Monday.
    Do the same for the Fourth Monday.
    Best wishes
    John M

  • How to get first day of the month by the given date?

    Now, is there function in CRM system that can get the first day of the month ?
    for example:
        input date is 2007/12/12, then return 2007/12/01 (the first day of month).
    Thank you~

    Hi ping,
    data: w_date type sy-datum ,
             w_temp(2) type c.
    w_date = '20071212'.
       w_temp = w_date+6(2).
       w_temp = w_temp - 1.
       w_date = w_date - w_temp.
    write / w_date.
    Plz Reward if useful,
    Mahi.

  • User Exit Variable for Calculating number of days in a month

    I need a query to calulate the number of days in a particular month upto the current date. For example if i give 26 Feb it should reutrn 25, if i enter 30march it should return 29 for any specific year. I have gone through some posts and understood that i need to create a formula variable (under calculated KF's) and then go to CMOD, create a project, then enancement Assignment RSAP0001 then EXIT_SAPLRSAP_001 and include a code in INCLUDE ZXRSAU01. But i have any clue of coding. Could someone give me the entire code and how to connect it to the formula variable KF in created. The technical name of the key figure is ZMDAYS. If i have made any mistakes or if there is another eaier alternative please let me know. I thankyou all for the help.

    Hi Uday,
    I have a few modifications in the code
    Data: xdate type d,
          ip_year(4) type N,
          ip_month(2) type N.
    Types : Begin of ty_month_days,
           month(2) type N,
           days(2) type N,
           End of ty_month_days.
    Data : it_month_days type ty_month_days occurs 0 with header line.
    ip_year = 2006.
    ip_month = 01.
    do 12 times.
        CONCATENATE ip_year ip_month '01' INTO xdate.
        xdate = xdate + 33.       "this date is in the next month
        xdate+6(2) = '01'.        "first day of next month
        xdate = xdate - 1.        "last day of xmonth
        it_month_days-month = xdate+4(2).       "number of days of xmonth.
        it_month_days-days = xdate+6(2).
        append it_month_days.
        ip_month = ip_month + 1.
    enddo.
    This code stores Month and No. of days in the internal table it_month_days.
    You can access this internal table for your calculations
    This should help.
    Regards,
    Praveen.
    Message was edited by: praveen mathew

  • How to get LASTDAY for each and every month between given dates..

    Hi Friend,
    I have a doubt,How to get LASTDAY for each and every month between given dates..
    for ex:
    My Input will be look like this
    from date = 12-01-2011
    To date = 14-04-2011
    And i need an output like
    31-01-2011
    28-02-2011
    31-03-2011
    is there any way to achieve through sql query in oracle
    Advance thanks for all helping friends

    Here's a 8i solution :
    select add_months(
             trunc(
               to_date('12-01-2011','DD-MM-YYYY')
             ,'MM'
           , rownum ) - 1 as results
    from all_objects
    where rownum <= ( months_between( trunc(to_date('14-04-2011','DD-MM-YYYY'), 'MM'),
                                      trunc(to_date('12-01-2011','DD-MM-YYYY'), 'MM') ) );
    The above two query is worked in oracle 11GActually the first query I posted is not correct.
    It should work better with
    months_between(
       trunc(to_date(:dt_end,'DD-MM-YYYY'),'MM'),
       trunc(to_date(:dt_start,'DD-MM-YYYY'),'MM')
    )Edited by: odie_63 on 12 janv. 2011 13:53
    Edited by: odie_63 on 12 janv. 2011 14:11

  • How to get the lock and block occured for the full day

    Hi,
         How to monitor the lock and blocks occurred for the full day? i need to get it by end of the day. is there any script for this?

    Hi,
         How to monitor the lock and blocks occurred for the full day? i need to get it by end of the day. is there any script for this?
    Why would you like to collect information about locks and let me tell you, you cannot collect information about ALL locks which were taken and even thinking about it is pointless.
    Coming to blocking if you have heavy system with huge concurrency there is bound to be blocking which is necessary and good for RDBMS but if the blocking remains for long time then this is a issue.
    There is DMV sys.dm_tran_locks which tell you what all locks are being taken. You can see various examples mentioned in DMV online documentation and can schedule the query to run every 5
    mins and insert its record in table which you can refer at end of the day.
    This task would be made very easy if you have Monitoring tool which gives you information in your mail every time blocking occurs I have Spotlight in my environment.
    If you are looking for doc for troubleshooting blocking  below is one you can refer
    http://support.microsoft.com/kb/224453
    Please mark this reply as answer if it solved your issue or vote as helpful if it helped so that other forum members can benefit from it.
    My TechNet Wiki Articles

Maybe you are looking for

  • Conditional drill based on level

    I have a requirement that users can drill down through a hierarchy in the standard way. However when they get to the bottom (leaf node) of the hierarchy then they should be directed to a different report which shows data for a selected measure(I cann

  • Client reads data from 2 servers parallely

    Hej I wonder if someone can help me. I wrote server/client program there client read text file fr server. I don't know khow to make client to read from 2 servers files parallelly - same time. I suppose I must start 2 threads i client program that rea

  • How do I load this program onto my PC?  I just bought it about 2 weeks ago.

    How can I tell if this program is loaded onto my computer?  I need to download a user manual or something so I know how to use it now that I have purchased it.

  • Sending a JMS message from a Servlet

    Hello All I�m using the Sun Java Sysytem Application Server and have been trying to implement a servlet which on receipt of a Post message, takes the message and sends it using JMS to a message queue. I�m developing my first web application so all is

  • 10.5.3:  Can't Create  Mobile Account

    I have a MacBook Pro that authenticates to Active Directory. When I try to create a Mobile Account [ System Preferences --> Accounts --> Mobile Accounts:Create ] I get prompted to "*Enter your password to create a mobile account*" However, it does no