Function CALCULATE_DATE and  leap year

Hi,
I need to substract some months from a date. I tried to use the standard function CALCULATE_DATE but it has a proble with leap years. If I execute it with the following parameters:
CALL FUNCTION 'CALCULATE_DATE'
     EXPORTING
          days        = '0'
          months      = '-24'
          start_date  = '20080229'
     IMPORTING
          result_date = X.
The value that I get in X is '00000000' because 2006 isn't a leap year. The problem is that the function doesn't know how to deal with this. The solution is very easy, buy if it's possible I would like to use a standard function.
Do you know if there are any standard function that has no problems with leap years?
Thanks and kind regards,
Marcela.

Hi Marcela,
Welcome to SDN.
You can try this FM <b>RP_CALC_DATE_IN_INTERVAL</b>.
data: wa_date like sy-datum.
call function 'RP_CALC_DATE_IN_INTERVAL'
         exporting
              date      = '20080229'
              days      = 0
              months    = 24
              signum    = '-'
              years     = 0
         importing
              calc_date = wa_date.
Hope this will help.
Regards,
Ferry Lianto

Similar Messages

  • Finding a function to get leap year

    Hi everybody!
    I need a function or code to find  if a year is  leap year or normal year.
    Thanks a lot of!
    DM

    Here is some code that I had in my bag of tricks.
    report zrich_0001 .
    parameters: p_datum type  sy-datum.
    * check if it is a leap year.
    data: march1 type sy-datum.
    data: last_day_feb type sy-datum.
    march1 = p_datum.
    march1+4(4) = '0301'.
    last_day_feb = march1 - 1.
    if last_day_feb+6(2) = '29'.
    write:/ 'This is a leap year'.
    endif.
    Regards,
    Rich Heilman

  • ICal and Leap Year

    I had set up a yearly recurring event for a birthday notification for Feb 29 (Leap Year) with a Alarm notification 6 days in advance of the day so I could be sure to send out a card in time, etc. etc. However, because there is no Feb 29 in calendar year 2010 it appears that the Alarm notification isn't working. Is this a bug or did I possibly do something wrong?

    Yes, I noticed this the other day but didn't make a connection with the US holidays. Odd quirk.

  • Bug with interval and leap years

    select to_date('2012-feb-29','yyyy-mon-dd') + interval '1' year as dt from dual;
    ORA-01839: date not valid for month specified
    01839. 00000 -  "date not valid for month specified"
    *Cause:   
    *Action:
    select to_date('2012-feb-29','yyyy-mon-dd') + interval '2' year as dt from dual;
    ORA-01839: date not valid for month specified
    01839. 00000 -  "date not valid for month specified"
    *Cause:   
    *Action:
    select to_date('2012-feb-29','yyyy-mon-dd') + interval '3' year as dt from dual;
    ORA-01839: date not valid for month specified
    01839. 00000 -  "date not valid for month specified"
    *Cause:   
    *Action:
    select to_date('2012-feb-29','yyyy-mon-dd') + interval '4' year as dt from dual;
    29-FEB-16 00:00:00
    select to_date('2012-feb-29','yyyy-mon-dd') + interval '1' day as dt from dual;
    01-MAR-12 00:00:00
    select to_date('2012-feb-29','yyyy-mon-dd') + interval '1' month as dt from dual;
    29-MAR-12 00:00:00The problem exists in 10.2.0.4 and 11.2.0.3
    Edited by: Sanjeev Chauhan on Feb 29, 2012 9:20 AM

    >
    considering this answered is simply sweeping an issue under the rug.
    >
    No - the question was answered. Did you read the reference that Paul cited? That is an ISO document and defines the standard.
    The section he referred to is General Rules 3b and states:
    >
    b) Arithmetic is performed so as to maintain the integrity of the datetime data type that
    is the result of the <datetime value expression>. This may involve carry from or to the
    immediately next more significant <datetime field>. If the data type of the <datetime value
    expression> is TIME, then arithmetic on the HOUR <datetime field> is undertaken modulo
    24. If the <interval value expression> or <interval term> is a year-month interval, then the
    DAY field of the result is the same as the DAY field of the <datetime term> or <datetime
    value expression>.
    c) If, after the preceding step, any <datetime field> of the result is outside the permissible
    range of values for the field or the result is invalid based on the natural rules for dates and
    times, then an exception condition is raised: data exception—datetime field overflow.
    Note: For the permissible range of values for <datetime field>s, see Table 11, "Valid values for fields
    in datetime items".
    >
    The relevant part of the above for year-month is
    >
    then the
    DAY field of the result is the same as the DAY field of the <datetime term> or <datetime
    value expression>.
    >
    DAY FIELD OF THE RESULT IS THE SAME AS THE DAY FIELD OF THE <DATETIME TERM>.
    That is, for 'year-month' the day cannot change and, per section c, if it does an exception is raised.
    That is how Oracle implements it. If the other databases implement it incorrectly then they have the problem not Oracle. The question was regarding Oracle's implementation so the question for Oracle is answered.
    That document was printed in 1994 but the current document, ISO-8601 2004, does not alter it at all.
    http://dotat.at/tmp/ISO_8601-2004_E.pdf

  • Time dimension wizard and leap year error?

    I've created a time dimension (rolap) using the wizard. I started with 2006 for 6 years. I used a fiscal calendar, 445, fiscal year start = jan 1, and month start = monday.
    The first 2 months of 2008 are ok. However, OWB ends the third month on March 31, 2008 and it should be March 30, 2008. It starts the next month on April 1, 2008 which is a Tuesday.
    I've tested with 10.2 and 11.1.
    Anybody seen this or have a solution?
    Garrett

    Garrett
    The start day that you specified as being Monday is in fact the week start day and not the month start day. In most cases these will both always land on the day of week you specify, but there are exceptions.
    The Fiscal year is split into Quarters and the start of each Quarter is based on the date of the start of the year, so if you started the year at Jan 6th, then the 2nd quarter will start on April 6th, and the third on July 6th and so on.
    In your case, an extra day is inserted in the 5th week of the first quarter so that the quarter can start at the correct date

  • HELP! Files won't open and previously had Firefox icon instead of DW icons!  Leap Year thing?

    Hi!  I went to update my website, which I do every night before the first day of every month and all the files had a FIrefox icon instead of the usual Dreamweaver one.  I have shut down, reinstalled DW MX 2004 but the files still do not open.  The icons have now changed to DW but they are not opening with right click, opening from Applications folder, double clicking the file, from get info and open with DW.  I am stumped. HELP!  Need to update for March 1st.
    Is it something to do with Leap Year 29th Feb?  Checked the clock in preferences but can't see how this affects it.
    Firefox is always updated but the latest version does not seem to be as efficient as previous upgrades.  We installed Chrome as well.  Do they interfere with each other?

    Hi Ken
    I wish the 7.1 updater download had helped but it didn¹t.  All the files
    were backed up before the installation, which went fine.
    Mac 10.5.8
    We used Disc Warrior to defrag the hard drive, which did not make a
    difference.
    We recently started using Chrome, so now have 3 browsers in the dock,
    Safari, Firefox and Chrome.  Do they interfere in any way with each other?
    The files, which I hadn¹t touched for a month as I update on a monthly
    basis, initially had the Firefox icon.
    Below is the message to send to Apple, which did not go through their report
    system!  A little disillusioned with the service!
    Model: iMac9,1, BootROM IM91.008D.B08, 2 processors, Intel Core 2 Duo, 3.06
    GHz, 4 GB
    Graphics: kHW_NVidiaGeForceGT130Item, NVIDIA GeForce GT 130,
    spdisplays_pcie_device, 512 MB
    Memory Module: global_name
    AirPort: spairport_wireless_card_type_airport_extreme (0x14E4, 0x8E),
    Broadcom BCM43xx 1.0 (5.10.91.22)
    Bluetooth: Version 2.1.9f10, 2 service, 0 devices, 1 incoming serial ports
    Network Service: Ethernet, Ethernet, en0
    Network Service: AirPort, AirPort, en1
    Serial ATA Device: WDC WD1001FALS-40K1B0, 931.51 GB
    Serial ATA Device: PIONEER DVD-RW  DVRTS08
    USB Device: Built-in iSight, (null) mA
    USB Device: Keyboard Hub, (null) mA
    USB Device: iLok, (null) mA
    USB Device: Apple Optical USB Mouse, (null) mA
    USB Device: Apple Keyboard, (null) mA
    USB Device: Deskjet 3840, (null) mA
    USB Device: BRCM2046 Hub, (null) mA
    USB Device: Bluetooth USB Host Controller, (null) mA
    USB Device: IR Receiver, (null) mA
    FireWire Device: d2 quadra (button), LaCie, 800mbit_speed
    Does not mean a thing to me.
    I am not late with updating the site, which is about New Zealand culture,
    month by month (www.englishteacher.co.nz). Probably only the third time I
    have been late since 2005. Not a huge amount of traffic, ~300 a month and
    free access to content but I would like to solve this problem.
    Could a reciprocal link have caused a problem?
    At my wits end.
    I really appreciate the help though.
    Cheers Yvonne
    From: Ken Binney <[email protected]>
    Reply-To: <[email protected]>
    Date: Wed, 29 Feb 2012 06:42:11 -0700
    To: Yvonne and Bill Hynson <[email protected]>
    Subject: HELP! Files won't open and previously had Firefox
    icon instead of DW icons!  Leap Year thing?
    Re: HELP! Files won't open and previously had Firefox icon instead of DW
    icons!  Leap Year thing?
    created by Ken Binney <http://forums.adobe.com/people/Ken+Binney>  in
    Dreamweaver - View the full discussion
    <http://forums.adobe.com/message/4236682#4236682>
    Not necessarily related, but did you also install the 7.1
    updater? http://www.adobe.com/support/dreamweaver/downloads_updaters.html
     Windows or MAC?
    Replies to this message go to everyone subscribed to this thread, not
    directly to the person who posted the message. To post a reply, either reply
    to this email or visit the message page:
    http://forums.adobe.com/message/4236682#4236682 To unsubscribe from this
    thread, please visit the message page at
    http://forums.adobe.com/message/4236682#4236682. In the Actions box on the
    right, click the Stop Email Notifications link. Start a new discussion in
    Dreamweaver by email
    <mailto:[email protected].ad
    obe.com>  or at Adobe Forums
    <http://forums.adobe.com/choose-container!input.jspa?contentType=1&container
    Type=14&container=2240>  For more information about maintaining your forum
    email notifications please go to
    http://forums.adobe.com/message/2936746#2936746.

  • Todate and AGO function in both Fiscal yer and Calendat year

    I want to create report having column with Todate and ago function formulas. I have to display the facts both in fiscal year and calendar year... how to do this? What value shall i choose in the content tab for the time dimension in this case? My fact table has values for each day...
    I am able to display only columns with fiscal year in time series function with timeDim.fiscal_year... similarly only calendar year with time seriese with calendar year columns... In my hierarchy, I have two branches for Time Dim...one is Fiscal and other is Calendar... and they both are at same level
    Help!

    I have an answer for you...Since you have a correctly defined time dimension (with branches - Fiscal Year->Fiscal Qtr ->Fiscal Month->Fiscal Week and Calendar Year->Cal Qtr->Cal Month->Cal Week->Cal that I assume have the common Child level - Day...) - you should have no problem building time-series logical columns
    In TODATE and AGO you must use relevant Time Dim Level - for example:
    AGO (Column, TimeDim.FiscalYear, 1) = would give you data for previous fiscal year
    AGO (Column, TimeDim.CalYear, 1) = would give you data for previous calendar year
    same goes for qtrs, months, weeks
    If you want to take it to the lowest level Day - it won't matter if you pick Fiscal or Calendar since it's essentially the same.
    I hope this is helpful

  • Leap Year and Schema & Rules on Time Management

    Hello,
    On Time management, do you know how to configure on Schema & Rules if the year is a leap year?
    Thanks, julien
    Edited by: Julien on May 6, 2009 6:33 PM

    Thanks for all,
    My solution below :
    ZFA/ 008 ACTIO ZFAF                    Leap Year
    ZFAF*****         PPCYGZFA1  NEXTR A
    ZFAF*****        APPCYGZFA2  NEXTR B
    ZFAF*****        BPPCYGZFA3  NEXTR C
    ZFAF*****        CZPAYTP 1
    ZFAF1****         DHRS=DINR2 HRS-DINR4 HRS+DINR6 ADDDBINR7ZHRS?1
    ZFAF1*****         HRS=365   ADDDBINJAZ
    ZFAF1****=         HRS=366   ADDDBINJAZ
    ZFA1*****         ZHRS=BCURYRHRS/400   ADDDBINR1ZROUNDH>60 PAYTP 1
    ZFA11****         DHRS?DINR1
    ZFA11*****         HRS=0     ADDDBINR2Z
    ZFA11****=         HRS=1     ADDDBINR2Z
    ZFA2*****         ZHRS=BCURYRHRS/100   ADDDBINR3ZROUNDH>60 PAYTP 1
    ZFA21****         DHRS?DINR3
    ZFA21*****         HRS=0     ADDDBINR4Z
    ZFA21****=         HRS=1     ADDDBINR4Z
    ZFA3*****         ZHRS=BCURYRHRS/4     ADDDBINR5ZROUNDH>60 PAYTP 1
    ZFA31****         DHRS?DINR5
    ZFA31*****         HRS=0     ADDDBINR6Z
    ZFA31****=         HRS=1     ADDDBINR6Z

  • Get previous year from leap year

    Hi all,
    I'm stuck here trying to get the previous year for the current year, I tried these function module but didn't work, CCM_GO_BACK_MONTHS and CALCULATE_DATE.
    The problem is, in the leap year, there's Feb 29th, so I want to get 1 year before the date I enter, 2008 is a leap year, when I entered feb 29th 2008, then used the FM, then it showed me Feb 29th 2007, but 2007 doesn't have Feb 29th.
    Any advice? thanks!

    Try                                                                               
    /SAPNEA/J_SC_CALENDAR          Calendar
    /SAPNEA/JSC_LEAP_YEAR          Leap year check between two date
                                                                                    EAU0
    ISU_LEAP_DAYS_BETWEEN_2_DATES
                                                                                    FF04
    FIMA_LEAP_DAYS_BETWEEN_2_DATES
                                                                                    FV02
    LEAP_DAYS_BETWEEN_TWO_DATES                                  
    You can also look at class "CL_HRSEN00_LEAP_DAY_TOOLS"
    ^ Saquib

  • How to Calculate Leap Year ago in OBIEE 11g

    Hi Gurus,
    I have one fact table and having one measure column. I have to calculate current year and Last year.
    Using Time series function (Todate,Ago) have calculated current year as well last year also.
    The problem is Current year is showing correct value only but Last year was showing wrong data.
    We found the problem is Leap year, last year FEB month is having 29 dates. Due to this we are getting wrong date.
    Kindly suggest me how to achieve this requirement.
    Thanks

    Hi Gurus,
    How to resolve Leap Year calculation in OBIEE 11g.
    The problems is Year Ago column.
    Please suggest me how to resolve this.
    Thanks

  • Leap year issue

    Hi friends,
    I have a problem in one of the existing codes.
    The cancellation amount is calculated for a range of dates.
    Say the active line item has a start date of  01.03.2006 and end date of  01.03.2012 say (B).
    Now if a rejection/Cancellation is put on date 01.05.2007 (A), the current program is calculating a value
    based on the diffrence of days (B - A).
    then this cancelled amnt =  the no of cancelled days * (a constn value * 12 / 365).
    Now I want to modify my logic in such a way that the leap is also accounted.
    If I use the same dates , i realise that 2008 is the leap yr.
    So how can i modify my calculation for the range if it contains a leap yr.
    Please suggest something on this, as it will be really helpful.
    Thanks,
    Sapna Agarwal

    Hi Sapna,
        try to use the FM /SDF/CMO_DATETIME_DIFFERENCE, it will take care of the leap year, just pass the two dates for which you want the difference.
    CALL FUNCTION '/SDF/CMO_DATETIME_DIFFERENCE'
    EXPORTING
       DATE1                   = s_date
    *   TIME1                  =
       DATE2                   = e_date
    *   TIME2                  =
    IMPORTING
       DATEDIFF                = DATEDIFF
    *   TIMEDIFF               =
    *   EARLIEST               =
    EXCEPTIONS
       INVALID_DATETIME        = 1
       OTHERS                  = 2
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    if the gap is for more one year than you have to do the calculation year wise only, in this case use the fm '/SAPNEA/JSC_LEAP_YEAR' that which year is a leap year. And than go for a IF condition while calculating either it should be 365 or 366 days.
    With luck,
    Pritam.

  • Leap Year

    Hi Everyone..
    I have two columns called base date and final due date from which we calculate the number of days. Can someone tell me how to calculate leap year in OBIEE.

    Hi
    Thanks for your reply. I am able to calculate the number of days using the above function TIMESTAMPDIFF(SQL_TSI_DAY,Day1, Day2). But my issue is to calculate leap year.
    eg : No of days >0 and < =365 , its 1st year
    if No of days >365 and < = 730 , its 2nd year.
    In this i need to verify if there is any leap year coming in btw like if No of days is 366 then ?
    Thanks in advance for the reply.

  • Leap Year Handling

    Hi All,
    I just want to get the exactly one year previous date by using the below query: for the leap year...
    update day
    SET FLAG = 'Y'
    WHERE PERIOD_DATE BETWEEN TRUNC(ADD_MONTHS(TO_DATE(20050228,'YYYYMMDD'),-12),'MON') and
    ADD_MONTHS(TO_DATE(20050228,'YYYYMMDD'),-12)
    In the same time while we use the same query for the leap year date:
    select * from day
    WHERE PERIOD_DATE BETWEEN TRUNC(ADD_MONTHS(TO_DATE(20080229,'YYYYMMDD'),-12),'MON')
    AND TO_DATE(20080229,'YYYYMMDD') + NUMTOYMINTERVAL(-1,'YEAR')
    I receive the following error - ORA-01839: date not valid for month specified.
    Problem:FLAG was incorrectly set to 'Y' for Feb 29 in 2004 during the report processing of Feb 28 data. Because of this, the extra day of Feb 29 2004 of Sales data was incorrectly being added to a report, thus overstating MTD sales of Feb 28 2004 by one full day. This appears to be caused by the fact that there were 28 days in Feb 2005 and 29 days in Feb 2004 becuase of the leap year. This will not cause problems until the next leap year.
    Can you please give me the resolution of the above.
    Thanks & Regards,
    Satheesh
    Message was edited by:
    user565141
    Message was edited by:
    user565141

    Hi Sateesh,
    I love your question, I have been writting quite often about this.
    ADD_MONTH is not the correct function to use, neither y2m interval.
    First, you need to define what is 2004-02-29 + 1 year. In most laws I found on the net (like majority and retirement policies), a leap-year baby will have his birthday on March 1st in non-leap years. If you have a contract, you must define this too.
    ex:
    update day set flag='Y'
      where period_date between
        trunc(ADD_MONTHS(:d,-12),'MON') and
        case to_char(:d,'MMDD')
          when '0228' then add_months(trunc(:d,'Y'),-12)+58
          else add_months(:d,-12) end;another approach would be
    where to_number(to_char(period_date,'YYYYMMDD')) between
      to_number(to_char(:d,'YYYYMM"00"'))-10000 and
      to_number(to_char(:d,'YYYYMMDD'))-10000;but if you have an index on period_date, the first solution may be more efficient
    Message was edited by:
    Laurent Schneider
    58 not 59
    Message was edited by:
    Laurent Schneider
    depending on how you define 29Feb -1Y, you could add
          when '0229' then add_months(trunc(:d,'Y'),-12)+59

  • Loading leap year date using SQL*Loader

    Hello,
    I have a problem loading a date '29/02/2000' using SQL*Loader. This date is on a leap year. I'm getting an error message from SQL*Loader as 'ORA-01839: date not valid for month specified'. My colleague and I have tried using various date functions to convert the data into date, but no luck.
    I would appreciate any helps,
    Bruce

    Thanks for your help, I found the bug on my control file. I was using the RTRIM function to remove bad timestamp such as '29/02/2000 0:00:00'. So instead of using this statement:
    LOG_DATE DATE "DD/MM/RRRR" "RTRIM(:LOG_DATE,'0:00:00')"
    I was using the statement below with a space before the '0:00:00' string literal, with the intention to remove a space also:
    LOG_DATE DATE "DD/MM/RRRR" "RTRIM(:LOG_DATE,' 0:00:00')"
    Well, it turned out that if there was a space before the string literal, RTRIM function would trim the matching string plus any '0' characters from the right, including the '000' that belongs to '2000'. Thus, the error.
    Thanks again,
    Bruce

  • Bug or error when handling leap years with WDS/DS

    Hi all,
    I discovered a difference in outcome with Build and Debug (without screens) and Build and Debug with Web Determinations or Determinations Server when calculating days within leap years.
    I use the function DayDifferenceInclusive to calculate the amount of days in an insurance period.
    the amount of days of the insurance period = DayDifferenceInclusive(the start date of the insurance, the end date of the insurance)
    With the regression tester or Build and Debug (without screens) I get the following outcome for the following input:
    *93 = DayDifferenceInclusive(02-29-2008, 05-31-2008)*
    When we use Web Determinations or Determinations Server we get the value of *92* for the exact same input data when it should be 93.
    Is this a bug in the java code? How can we fix this or is there a work around for it?
    We're in the middle of System Integration Testing for a huge project so help is much appreciated!
    Best regards,
    Niels Roest

    Niels,
    thanks for that - and it looks like in the Netherlands daylight savings started on the 30th of March 2008, which as far as I know is the trigger for this error.
    I have reproduced the issue against 10.1 using the period 01 October 2010 to 30 October 2010, which contains the date that daylight saving started in Australia.
    As for ways to work around the issue, I can offer 3:
    * wait for 10.2 - it's in beta at the moment (though given your opening comments, this might not be an option for you)
    * set your server locale to one that doesn't have DST
    * work around the issue in rules:
    Firstly, the issue is that the shipping version fails because it doesn't take into account that one of the days is shorter than the standard 24 hours.
    The trick is to replace the DayDifference function with the HourDifference function and round to the nearest number of days.
    So given a rule that looks like:
    the result = DayDifference(date one, date two)
    it can be rewritten as:
    The result = round(HourDifference(date one at 00:00:00, date two at 00:00:00) / 24, 0)
    * the whole "at 00:00:00" is necessary because HourDifference works on datetimes, not dates.
    Sorry for the hassle.
    Regards
    Andrew

Maybe you are looking for