Months between two date

There two ways of finding months between two dates
ROUND((Date1 – Date2) / 365.25 * 12,2) and
ROUND(months_between(date1,date2),2) There is a slight difference between output from these two.
I think the result from the second statement should be more accurate, confirm?
Abhishek

AbSHeik wrote:
There two ways of finding months between two dates
ROUND((Date1 – Date2) / 365.25 * 12,2) and
ROUND(months_between(date1,date2),2) There is a slight difference between output from these two.
I think the result from the second statement should be more accurate, confirm?
AbhishekHi Abhishek,
I also agree with this.
Coz 365.25 = (365 + (1/4))
This 0.25 actually the extra year of a Leap Year, distributed equally among 4 years. But, when the 1st formula is evaluated, the calculation might cause difference...
So as far as Oracle is concerned, MONTHS_BETWEEN should be used.
Please rectify me if i'm wrong.
Ranit B.

Similar Messages

  • How to Calculate number of months between two dates

    Hi All,
       In one of the fomr developments, I have to calculate the
    Number of Days
    Number of Months ( Considering Leap Year) provided by the dates, end user enters in the form,
    After going thorugh some forum discussion, I have come to know about so many things which were not clear till now.
    I have gone through various forums too,  some one suggets to make use of FORM CALC and some other JAVA SCRIPT. But the logic i want to build in java script.
    The most interesting point is the DATE object is not getting created when i write  the below code
      var startDate = new DATE(oYear, oMonth, oDay);
    I am still not clear, that really the date object gets created in Adobe form If so the why the alert box is getting populated when i write below lines
    var oTemp = startDate.getFullYear();
    xfa.host.messagebox(oTemp);
    So, there are so many unclear things,
    If any one can help me by suggesting the approach and how to build the logic in the JavaScript I would be really thankful
    Regards
    PavanChand

    Hi,
    ChakravarthyDBA wrote:
    Hi
    I want number of Sundays between two dates
    example
    number of Sundays count between '01-04-2013' and '30-04-2013' in one select query I have to include this as sub query in my select statement.Here's one way:
    SELECT       early_date
    ,       late_date
    ,       ( TRUNC (late_date + 1, 'IW')
           - TRUNC (early_date,        'IW')
           ) / 7       AS sundays
    FROM       table_x
    ;This does not depend on your NLS settings.
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and also post the results you want from that data.
    Point out where the statment above is getting the wrong results, and explain, using specific examples, how you get the right results from the given data in those places.
    Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
    See the forum FAQ {message:id=9360002}

  • Need Help on List of Months between Two Dates

    Hello everyone,
    I have a table which has startdate & enddate, and need a SELECT statement to list all months between these two dates for each given ID.
    I did some test, and could not figure out how to get the startdate & enddate from testing table (instead of hard code them) in the select statement.
    Could anybody please help on it (Oracle 11gR2),
    Thanks in advance!!!
    create table testing(
    id          number,
    start_date  date,
    end_date    date);
    insert into testing values(100, to_date('05-FEB-2011', 'DD-MON-YYYY'), to_date('28-MAY-2011', 'DD-MON-YYYY'));
    insert into testing values(200, to_date('20-JUN-2011', 'DD-MON-YYYY'), to_date('28-DEC-2011', 'DD-MON-YYYY'));
    commit;
    select * from testing;
            ID START_DAT END_DATE
           100 05-FEB-11 28-MAY-11
           200 20-JUN-11 28-DEC-11
    Elapsed: 00:00:00.01
    *for testing.id = 100:*
    select to_char(add_months(to_date('05-FEB-2011', 'DD-MON-YYYY'), l - 1), 'YYYY-Mon') Dates
    from (select level l
           from dual
        connect by level <= months_between(trunc(to_date('28-MAY-2011', 'DD-MON-YYYY'), 'MONTH'),
                                           trunc(to_date('05-FEB-2011', 'DD-MON-YYYY'), 'MONTH')) + 1);
    DATES
    2011-Feb
    2011-Mar
    2011-Apr
    2011-May
    Elapsed: 00:00:00.01
    *for testing.id = 200:*
    select to_char(add_months(to_date('20-JUN-2011', 'DD-MON-YYYY'), l - 1), 'YYYY-Mon') Dates
    from (select level l
           from dual
        connect by level <= months_between(trunc(to_date('28-DEC-2011', 'DD-MON-YYYY'), 'MONTH'),
                                           trunc(to_date('20-JUN-2011', 'DD-MON-YYYY'), 'MONTH')) + 1);
    DATES
    2011-Jun
    2011-Jul
    2011-Aug
    2011-Sep
    2011-Oct
    2011-Nov
    2011-Dec
    7 rows selected.

    SQL> select * from testing
      2  /
            ID START_DAT END_DATE
           100 05-FEB-11 28-MAY-11
           200 20-JUN-11 28-DEC-11
    SQL> select  id,
      2          to_char(add_months(start_date,column_value - 1),'YYYY-Mon') dates
      3    from  testing,
      4          table(
      5                cast(
      6                     multiset(
      7                              select  level
      8                                from  dual
      9                                connect by add_months(trunc(start_date,'MM'),level - 1) <= end_date
    10                             )
    11                     as sys.OdciNumberList
    12                    )
    13               )
    14    order by id,
    15             column_value
    16  /
            ID DATES
           100 2011-Feb
           100 2011-Mar
           100 2011-Apr
           100 2011-May
           200 2011-Jun
           200 2011-Jul
           200 2011-Aug
           200 2011-Sep
           200 2011-Oct
           200 2011-Nov
           200 2011-Dec
    11 rows selected.
    SQL> SY.

  • Create a table with all the months between two dates

    Hi all,
    I have a purchase table recording individual purchases. One of the fields is my Date field (date of purchase).
    I would like to create a table 'All_months' with two entries ('month_no' and 'month') which will be based on the first and last date in the purchase table. Assuming the first purchase recorded in my purchase table was on the 12th of January 2008, the table should have the following structure:
    month_no month
    1 12JAN2008
    2 12FEB2008
    3 12MAR2008
    It should continue in this fashion up-to the month where the last purchase was recorded.
    I have been struggling with creating the query that would do that for days now and can't find anything when asking Mr Google.
    Thanks,
    Chris

    Welcome to the forum!
    Here's one way:
    CREATE TABLE     all_months
    AS
    SELECT     LEVEL                    AS month_no
    ,     ADD_MONTHS ( first_date
                 , LEVEL - 1
                 )               AS month     
    FROM     (
              SELECT     MIN (date_of_purchace)     AS first_date
              ,     MAX (date_of_putchase)     AS last_date
              FROM     purchase
    CONNECT BY     LEVEL <= 1 + MONTHS_BETWEEN ( TRUNC (last_date,  'MONTH')
                                 , TRUNC (first_date, 'MONTH')
    ;Do you really need a table like this? Every time you change the data in the purchase table, you won't know if all_months is still accurate or not. You can derive all_months in a sub-query every time you need it, or make all_months a view instead of a table.
    Edited by: Frank Kulash on Jun 14, 2012 5:57 AM

  • Calculation of MONTHS , YEARS , & DAYS between two dates

    Hi Experts,
      Currently i am using this functional Module. which calculates the number of months between two dates.
       CALL FUNCTION 'FIMA_DAYS_AND_MONTHS_AND_YEARS'
             EXPORTING
                  I_DATE_FROM = ITAB_PER-BEGDA
                  I_DATE_TO   = ITAB_PER-ENDDA
             IMPORTING
                  E_MONTHS    = CMONTHS.
      BUT this functional module Rounding off the Month...Say ..if the total numbr of days between from & to date is 105 it is showing as 4 months ...
      <b>Is there any other Functional Module</b> ????which Calculates the EXACT MONTH between two dates...(in the above case the month is expected to be 3 only since it is 105 days only)..
      Kindly help me regarding this....

    lakshimiraja,
    You can use this function module.
    report zrich_0003
           no standard page heading.
    data: duration_in_months type i.
    parameters: s_date type sy-datum,
                e_date type sy-datum.
    call function 'DURATION_DETERMINE'
    exporting
       unit                             = 'MON'
       factory_calendar                 = 'P6'    "  Your factory calendar
    importing
       duration                         = duration_in_months
    changing
       start_date                       = s_date
       end_date                         = e_date
    exceptions
       factory_calendar_not_found       = 1
       date_out_of_calendar_range       = 2
       date_not_valid                   = 3
       unit_conversion_error            = 4
       si_unit_missing                  = 5
       parameters_not_valid             = 6
       others                           = 7.
       write:/ duration_in_months.
    Don't forget to reward if useful...

  • How to calculate the month difference between two date char. in Query?

    Customers would like to see how many months passed between two date type of characteristics (e.g., the month difference between the current date and the scheduled delivery date in the record) and put the result into the column as KF. 
    We would have to grab the fiscal year/period kind of value and then do the subtraction, e.g., if the current date value is 2/28/2008 and the scheduled delivery date value in the record is 12/01/2007, the correct result should be 2 month difference between these two date values, but could someone here give us the technical light on how to make this happen in query design?
    Thanks and we will give you reward points for the correct anwsers!

    Hi Kevin,
    The Badi is RSR_OLAP_BADI.
    You can create an implementation using Transaction  SE18.
    The implementation is per cube and is defined in the filters.
    In the Implementation you have the following methods :
    1. Define : Here you will provide the Keyfigure you need as a virtual one.
    2. Initilialize : Any Init Function you want to do.
    3. Compute. This is called per datarecord and here you can cimpute your value.
    Hope this helps.
    Pralay Ahluwalia

  • Find the difference between two dates for the specific month and year

    Hi,
    I have two dates, start date is 30/12/2012 and end date is 04/01/2013. Using datediff I found the difference of days between two dates. But I find the no of days in January 2013. ie output is 4 instead of 6. I input month and year to find the no of days
    for that date. In this case I input Jan 2013. How can I sql this ?

    I don't understand how most of the answers provided here not analytically solving the problem with many cases possible.
    First let me understand you:
    You have 2 dates range and you want to calculate day range for specific month and year between the original date range.
    declare @for_month int = 1 --January
    declare @for_year int = 2013
    declare @StartDate date = '2012-12-20'
    declare @EndDate date = '2013-01-04'
    SELECT
    CASE
    WHEN (DATEPART(MONTH, @StartDate) = @for_month and DATEPART(MONTH, @EndDate) = @for_month) and ((DATEPART(YEAR, @StartDate) = @for_year or DATEPART(YEAR, @EndDate) = @for_year)) THEN
    DATEDIFF(DAY, @StartDate,@EndDate)
    WHEN (@StartDate < cast(CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date)) and (@EndDate between (cast(CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date)) and (cast(DATEADD(d, -1, DATEADD(m, DATEDIFF(m, 0, cast( CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date)) + 1, 0)) as date))) THEN
    DATEDIFF(DAY, DATEADD(MONTH, DATEDIFF(MONTH, -1, @EndDate)-1, 0),@EndDate)
    WHEN (@EndDate > cast(DATEADD(d, -1, DATEADD(m, DATEDIFF(m, 0, cast( CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date)) + 1, 0)) as date)) and (@StartDate between (cast(CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date)) and (cast(DATEADD(d, -1, DATEADD(m, DATEDIFF(m, 0, cast( CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date)) + 1, 0)) as date))) THEN
    DATEDIFF(DAY, @StartDate,DATEADD(d, -1, DATEADD(m, DATEDIFF(m, 0, @StartDate) + 1, 0))) + 1
    WHEN ((DATEDIFF(DAY, @StartDate, cast(DATEADD(d, -1, DATEADD(m, DATEDIFF(m, 0, cast( CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date)) + 1, 0)) as date)) >= 0) and (DATEDIFF(DAY, cast(CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date), @EndDate) >= 0)) THEN
    DATEDIFF(DAY, cast( CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as datetime), DATEADD(d, -1, DATEADD(m, DATEDIFF(m, 0, cast( CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as datetime)) + 1, 0))) + 1
    ELSE
    0
    END as [DD]
    I don't know how you calculate day range between 01/01/2013 and 04/01/2013
    is 4, it is actually is 3 but if that is the case, you can add 1 from the condition.

  • 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

  • Date difference between two dates

    hi All,
    i have to right a stored proc to find the difference between two dates. 
    for example of i give
    startdate as 4/1/2015 and enddate 14/1/2015
    i should get 1 year , 10 days and 0 months .
    i have tried the DateDiff function but it does not calculate the leap year.
    please help.

    DECLARE @from datetime
    DECLARE @to   datetime
    SET @from = '20150104  8:00'
    SET @to   = '20150114  10:30'
    SELECT DATEDIFF(minute,@from, @to) % 60 as Minutes
    SELECT (DATEDIFF(minute,@from, @to) / 60) % 24 as Hours
    SELECT DATEDIFF(minute,@from, @to) / (60 * 24) as Days
    SELECT DATEDIFF(month,@from, @to) as Months
    SELECT DATEDIFF(year,@from, @to) as Year
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • List Months between a date range

    Hi, I'm trying to list the months between a given date range in an ABAP report to generate a MIS report(ALV).. Say I have 2 date ranges, 01.01.2006 to 01.04.2006.. I want to list
    Jan 2006
    Feb 2006
    Mar 2006
    Apr 2006.. Any FM in SAP to get this OP..

    hi vivek,
    use this function module to get months beween two dates
    1. MONTHS_BETWEEN_TWO_DATES   or
    2. MONTHS_BETWEEN_TWO_DATES_NEW
    please reward the point if you are satisfied with answer
    thanks,
    john.

  • How can I calculate the maximum number of days between two dates in a range of dates?

    I have a column of dates spanning the couse of a few months.  I would like to know if I can calculate the maximum number of days between each row and display the highest number.  I currently have another column that calculates the days betwen the rows and I am currently just looking at the totals and highlighting the highest period.
    Is this possible?  Any help or suggestions are appreciated.
    Thank you,
    Trevor

    This sounds totally possible,  Can you post a screen shot of your table to make responding more focused?  If you mean you want to:
    A) compute the difference (in days) between two date in the same row, then
    B) find the max duration (in days)
    Here is my take on this problem:
    D2 = C2-B2
    select D2 and fill down
    F1=MAX(D)
    to perform the conditional formatting (to highlight the max duration) select column D, then set up conditional formatting as shown in the 1st image

  • How to calculate number of days between two date in Template design?

    Hello guys
    I have a situation where I have to create a template that returns data, and one of the thing of the existing report is that there is a column that is actually the number of days between start date and end date columns..
    So in template, how would I be able to do the same? I have start date and end date columns on the template, now when I created another column using expression like end date - start date and preview the template, I am getting errors saying :
    Caused by: oracle.xdo.parser.v2.XPathException: Cannot convert 03/31/2009 to number.
         at oracle.xdo.parser.v2.XSLStylesheet.flushErrors(XSLStylesheet.java:1534)
         at oracle.xdo.parser.v2.XSLStylesheet.execute(XSLStylesheet.java:521)
         at oracle.xdo.parser.v2.XSLStylesheet.execute(XSLStylesheet.java:489)
         at oracle.xdo.parser.v2.XSLProcessor.processXSL(XSLProcessor.java:271)
         at oracle.xdo.parser.v2.XSLProcessor.processXSL(XSLProcessor.java:155)
         at oracle.xdo.parser.v2.XSLProcessor.processXSL(XSLProcessor.java:192)
    Please advice
    Thanks

    Hi
    There is an extension function you can use, from the javadoc:
    date_diff
    public static long date_diff(java.lang.String format,
    java.lang.String fromDate,
    java.lang.String toDate,
    java.lang.String locStr,
    java.lang.String tzID)
    Method to get the difference between two dates in the given locale. The dates need to be in "yyyy-MM-dd" format. This function supports only Gregorian calendar.
    Parameters:
    format - the format to which the difference is required; allowed formats are y (for Year), m(for month), w(for week), d(for day), h(for hour), mi(for minute), s(for seconds) and ms(for milliseconds)
    fromDate - the first date
    toDate - the second date
    locStr - locale string -> lang-Territory
    tzID - timezone ID ->http://java.sun.com/j2se/1.4.2/docs/api/java/util/TimeZone.html
    Returns:
    the difference in dates in the desired format
    For example
    <?xdoxslt:date_diff(‘d’,’2009-09-14’, ‘2009-09-20’,’en-US’,1)?>
    give a result of 6
    You can substitute in columns for the dates, just remember the date format required.
    Regards
    Tim

  • I wanted to know how do you calculate the number of days between two dates

    i wanted to know how do you calculate the number of days between two dates in java ? i get both the dates from the database. i guess there are many issues like leap year and Febuary having diff no of months ..etc.

    thanks..
    I solve my problem as
    public class MyExample {
        public static void main(String a[]) {
            String stdate = "2009-03-01";
            java.sql.Date currentDate = new java.sql.Date(System.currentTimeMillis());
            java.sql.Date preDate = java.sql.Date.valueOf(stdate);
            System.out.println(currentDate);
            System.out.println(preDate);
    //        int dateCom = preDate.compareTo(currentDate);
    //        System.out.println(dateCom);
            long diff = currentDate.getTime() - preDate.getTime();
            int days = (int) Math.floor(diff / (24 * 60 * 60 * 1000));
             System.out.println(days);
    }

  • How to calculate  number of sundays and saturdays between two Dates

    friends i want to calculate how many Sundays come in two Dates
    i have tried following code which is hard coded i have to impliment method which can give me number of Sundays between two Dates
    please help me
    import java.util.Date;
         import java.text.DateFormat;
         import java.text.SimpleDateFormat;
         import java.util.Calendar ;
         import java.util.GregorianCalendar;
    public class DateDiffCalculator     {
         private static final SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MMM-dd");
    public DateDiffCalculator()     {
         public static Date getDate (String date) throws Exception {
    //log.debug(" "+date);
              return SDF.parse(date);
    public static Date getDate (Date date) throws Exception {
    // log.debug("date is "+date);
              return getDate(SDF.format(date));
    public static long getDiffInDays(Date d1,Date d2)     {
         boolean isdiffGreaterThanYear=false;
         long diffInMilliSeconds=d1.getTime()-d2.getTime();
         return diffInMilliSeconds/(1000*60*60*24);
    public static int getYear(String date)     {
              //String[] day=     {Sun,Mon,Tue,Wed,Thu,Fri,Sat};
              Integer     year=new     Integer(date.substring(0,4));
         return year.intValue();
    public static int getMonth(String date)     {
              //String date.substring(5,7);
              System.out.println(" "+date.substring(5,8));
              String     m= date.substring(5,8);
              int month=0;
              if(m.equalsIgnoreCase("Jan"))     {
              month=1;
              if(m.equalsIgnoreCase("Feb"))     {
              month=2;
              if(m.equalsIgnoreCase("Mar"))     {
              month=3;
              if(m.equalsIgnoreCase("Apr"))     {
              month=4;
              if(m.equalsIgnoreCase("May"))     {
              month=5;
              if(m.equalsIgnoreCase("Jun"))     {
              month=6;
              if(m.equalsIgnoreCase("Jul"))     {
              month=7;
              if(m.equalsIgnoreCase("Aug"))     {
              month=8;
              if(m.equalsIgnoreCase("Sep"))     {
              month=9;
              if(m.equalsIgnoreCase("Oct"))     {
              month=10;
              if(m.equalsIgnoreCase("Nov"))     {
              month=11;
              if(m.equalsIgnoreCase("Dec"))     {
              month=12;
              return month;
         public static int getDay(String date)     {
              Integer     day=new     Integer(date.substring(9,11));
         return day.intValue();
    public static int getNumberofSundays(String d1,String d2) throws Exception     {
              //d1 is leave start date d2 is leave end date
              // get object in Date form
                   Date date1=getDate(d1);
                   Date date2=getDate(d2);
              // now get calender objects from it
              GregorianCalendar c1= new GregorianCalendar(getYear(d1),getMonth(d1),getDay(d1));
              GregorianCalendar c2= new GregorianCalendar(getYear(d2),getMonth(d2),getDay(d2));
              // get period
              long leavePeriod = getDiffInDays(date1,date2);
         return 12; // it should return number of sundays but we type 12 to perform compilation
    public static void main(String[] arg)throws Exception     {
    System.out.println(" "+getNumberofSundays("2005-Oct-07","2006-Mar-01"));
    }

    thanks now i have modified the get Month Code
    as follows
    public static int getMonth(String date)     {
              //String date.substring(5,7);
              System.out.println(" "+date.substring(5,8));
              String     m= date.substring(5,8);
              int month=0;
              if(m.equalsIgnoreCase("Jan"))     {
              month=0;
              if(m.equalsIgnoreCase("Feb"))     {
              month=1;
              if(m.equalsIgnoreCase("Mar"))     {
              month=2;
              if(m.equalsIgnoreCase("Apr"))     {
              month=3;
              if(m.equalsIgnoreCase("May"))     {
              month=4;
              if(m.equalsIgnoreCase("Jun"))     {
              month=5;
              if(m.equalsIgnoreCase("Jul"))     {
              month=6;
              if(m.equalsIgnoreCase("Aug"))     {
              month=7;
              if(m.equalsIgnoreCase("Sep"))     {
              month=8;
              if(m.equalsIgnoreCase("Oct"))     {
              month=9;
              if(m.equalsIgnoreCase("Nov"))     {
              month=10;
              if(m.equalsIgnoreCase("Dec"))     {
              month=11;
              return month;
    but question remains same how to calculate number of Sundays Between 2 Dates

  • No.of feb 29's between two dates

    Hi,
    I would like to calculate feb29's between two dates currently using connect by level but it causes performance issue(50M data to process)
    (SELECT SUM(DECODE(TO_CHAR(start_date + LEVEL - 1,'dd-mon'),'29-feb',1,0)) FROM dual CONNECT BY LEVEL <= SYSDATE - start_date+1) 'NO.OF.FEB29'Using Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit
    Thanks-

    Small change required..
    with t as
    (select sysdate-10000 start_dt,to_date('01-Mar-2012','dd-Mon-yyyy') end_dt from dual)
    select start_dt,end_dt,st_year,end_year,sum(case when mod(yr,400)=0 then 1
                    when mod(yr,4) = 0 then 1
               else 0 end) cnt
    from(     select start_dt,end_dt,st_year,end_year,st_year+rownum-1 yr
         from (
              select  start_dt,end_dt,
                   extract(year from start_dt)+
                     case when extract(month from start_dt) < 3 then 0 else 1 end st_year,
                   extract(year from end_dt)+
                     case when extract(month from end_dt) >= 3 then 0 else -1 end end_year
              from t)
         connect by st_year+rownum-1 <= end_year
    group by start_dt,end_dt,st_year,end_year
    SQL> /
    START_DT    END_DT         ST_YEAR   END_YEAR        CNT
    11-may-1985 28-feb-2012       1986       2011          6
    SQL> /
    START_DT    END_DT         ST_YEAR   END_YEAR        CNT
    11-may-1985 29-feb-2012       1986       2011          6
    SQL> /
    START_DT    END_DT         ST_YEAR   END_YEAR        CNT
    11-may-1985 01-mar-2012       1986       2012          7Edited by: jeneesh on Sep 26, 2012 11:44 AM
    formatted
    Edited by: jeneesh on Sep 26, 2012 12:07 PM
    Subqueries can be avoided, added for understanding purpose

Maybe you are looking for

  • ITunes 7.+Compatability with Ask the DJ --getting nowhere

    I have iTunes 7.0+ & Ask the DJ on my MacBookPro. When I drag tunes to ATDJ they get all bpm ect. but when I play them they're garbled then just stop. It only happens on MBP none of the other machines, I've erased the old copies & downloaded new soft

  • WS-ReliableMessaging - Not working as expected

    Hi @ll I just played around with the reliable sample that comes with WLS 9.2.1. I was wondering why there are no WS-RM req/res like CreateSequence or TerminateSequence on the wire ?o) There are WS-Addressing parts in the message but nothing I exepect

  • Use of I_CALLBACK_USER_COMMAND in ALV grid display

    Hi experts, When i am using the parameter I_CALLBACK_USER_COMMAND in grid display and when i click on BACK button, then the Function code for BACK button is not captured i.e. it does not go in the routine which i have written. But this is not the cas

  • Is there full installer file available for version 9.4.6

    Hi, Anyone know if there is a full installer file available for Acrobat Pro 9.4.6?  I know the product is EOL later this year but we still have users accessing this version prior to upgrading to version 11. The problem is the last full installer we h

  • Incident Report at Puerto Rico Store # 1118

    Today, February 10, 2014 at approximately 2:05 pm the following incident took place at your PR store #1118: While at your store I selected a product (Samsung Micro USB Connector). In order to comply with your store regulations, I left the selected pr