No.of feb 29 s between two dates

Hello

I would like to calculate feb29 between two dates currently using connect by level , but it causes the problem of performance (50 M of data)

(SELECT SUM (DECODE (TO_CHAR (start_date + LEVEL - 1,'dd - my '), 29 - feb', 1, 0)) double CONNECTION OF LEVEL < = SYSDATE - start_date + 1) ' no. OF. FEB29'
using Oracle Database 11 g Enterprise Edition Release 11.2.0.2.0 - 64 bit


Thank you-

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          7

Published by: JAC September 26, 2012 11:44
formatting

Published by: JAC September 26, 2012 12:07
Subqueries can be avoided, added the goal of understanding

Tags: Database

Similar Questions

  • Months between two dates

    Hello

    I have two dates. start date and end date.

    I want to extract months between two dates

    months should be as

    JAN

    FEB

    MAR

    for example.

    Start - 1-jan-2014

    date of end - 31 - dec - 2014

    How can I do this?

    Thanks and greetings

    CORINE

    You should always use the function MONTHS_BETWEEN...

    for example

    SQL > ed
    A written file afiedt.buf

    1 with t as (select date '' 2014-01-01 as start_date date ' 2014-12-31' as double end_date)
    2  --
    3 end of test data
    4  --
    5. Select to_char (add_months (start_date, rownum-1), 'My') by month
    6 t
    7 * connect by rownum<=>
    SQL > /.

    LUN
    ---
    Jan
    Feb
    Mar
    Apr
    May
    Jun
    Jul
    Aug
    Ms
    Oct
    Nov
    Dec

    12 selected lines.

    And if you want that they display, separated by commas...

    SQL > ed
    A written file afiedt.buf

    1 with t as (select date '' 2014-01-01 as start_date date ' 2014-12-31' as double end_date)
    2  --
    3 end of test data
    4  --
    5 Select listagg (to_char (add_months (start_date, rownum-1), 'My'), ',') group by month (order by rownum)
    6 t
    7 * connect by rownum<=>
    SQL > /.

    MONTH
    -----------------------------------------------------------------------------------------------------------------
    Jan, Feb, Mar, Apr, may, June, July, August, Sept, Oct, Nov, Dec

  • How to caluclate tat between two dates of a timestamp field

    Hello
    could help to caluclate days between two dates and unique timestamp filed with this
    query
    Select * from m_activity_transaction where actn_opp_id in)
    Select actn_opp_id in the m_activity_transaction where ACTN_ACTV_ID = 218
    Actn_opp_id group
    view count (*) > 1) and ACTN_ACTV_ID = 218
    order of actn_performed_on
    IAM get output is

    ACTN_ID ACTN_OPP_ID ACTN_PERFORMED_ON
    319415 95831 JANUARY 27, 12 AM 11.06.20.000000
    315249 95831 8 FEBRUARY 12 05.32.54.000000 PM
    301927 103509 20 DECEMBER 11 04.01.43.000000 PM
    301458 103509 19 DECEMBER 11 04.51.03.000000 PM
    294841 115840 10 JANUARY 12 03.20.12.000000 PM
    312062 115840 11 JANUARY 12 05.17.06.000000 PM

    Normand to caluclate number days between two dates like January 27, 12 AM 11.06.20.000000 and I 05.32.54.000000 8 February 12 PM where actn_id is unique AND ACTN_OPP_ID IS NOT UNIQUE.
    Thanks in advance,
    VVR.

    In this way.

    with data as
    (
    select 315249 a, 95831 b, to_date('27-JAN-12 11.06.20 AM', 'DD-MON-RR HH.MI.SS AM') dt from dual union all
    select 319415, 95831, to_date('08-FEB-12 05.32.54 PM', 'DD-MON-RR HH.MI.SS AM') from dual union all
    select 301927, 103509 , to_date('20-DEC-11 04.51.03 PM', 'DD-MON-RR HH.MI.SS AM') from dual union all
    select 301458 , 103509 , to_date('19-DEC-11 04.01.43 PM', 'DD-MON-RR HH.MI.SS AM') from dual union all
    select 363810 , 144656 , to_date('27-JUN-12 12.43.28 PM', 'DD-MON-RR HH.MI.SS AM') from dual union all
    select 363500 , 144656 , to_date('26-JUN-12 11.41.50 AM', 'DD-MON-RR HH.MI.SS AM') from dual union all
    select 363354 , 144656 , to_date('25-JUN-13 12.41.13 PM', 'DD-MON-RR HH.MI.SS AM') from dual
    )
    select a, b, diff_in_days
      from (
            select a, b, trunc(dt - lag(dt) over (partition by b order by dt, a)) diff_in_days
              from data
           ) tab
     where tab.diff_in_days is not null;
    
    A                      B                      DIFF_IN_DAYS
    ---------------------- ---------------------- ----------------------
    319415                 95831                  12
    301927                 103509                 1
    363810                 144656                 1
    363354                 144656                 362
    
  • photo selection between two dates

    In Photos

    It is possible to select photos between two dates?

    In Photos,.

    is it possible to select the photos between two dates?

    Thank you, thank you

    Yes.  With a smart album like this:

  • MaxL Script to clear the data between two dates

    Hi all

    I need advice to clear the data between two dates, I have three dimensions in my sketch, 'eno', 'hiredate' and the 'actualamount '.

    Now I need to erase the data between the date range, up to now, I have this script,

    Fix ("HireDate", "Eno")

    Difficulty (@relative ("00:00:00",0),@relative("eno",0)) 2015-07-15 "))

    CLEARDATA "sal."

    endfix

    ENDFIX

    These scripts only clears on a specific day, but I tried to write the script to clear between two dates, I surfed on a few sites, but no clear answers, finaanly came here, kindly help in this regard.

    Thanks in advance.

    Have you not tried the format of "startdate":"enddate" for example "August":"September."

    See you soon

    John

  • Dynamic calculation of the number of days between two dates in a table

    Hello

    I'm working on request where I dynamically calculate the number of days between two dates in a table.

    The calculation must be dynamic, i.e., when I recover the Start_date and End_date and move to the field following (call_duration) in the same row, the difference must be calculated dynamically in this area and make sure the field read-only.

    APEX version: 5.0

    Hi BO123,

    BO123 wrote:

    Hello

    I'm working on request where I dynamically calculate the number of days between two dates in a table.

    The calculation must be dynamic, i.e., when I recover the Start_date and End_date and move to the field following (call_duration) in the same row, the difference must be calculated dynamically in this area and make sure the field read-only.

    APEX version: 5.0

    one of the way to do this by calling ajax on change of end_date.

    See the sample code given below to fetch the resulting duration and making the field read only after calculation

    Step 1: Change your page

    under CSS-> Inline, put the code below

    .row_item_disabled {
      cursor: default;
      opacity: 0.5;
      filter: alpha(opacity=50);
      pointer-events: none;
    }
    

    Step 2: Create on demand Ajax process I say CALC_DURATION

    Please check Procces Ajax, see line 6.7 How to assign a value to the variable sent by ajax call

    Declare
      p_start_date  date;
      p_end_date    date;
      p_duration number;
    Begin
      p_start_date  := to_date(apex_application.g_x01);
      p_end_date    := to_date(apex_application.g_x02);
    
       --do your calculation and assign the output to the variable p_duration
      select p_end_date - p_start_date into p_duration
        from dual;
    
      -- return calculated duration
      sys.htp.p(p_duration);
    End;
    

    Step 3: Create the javascript function

    Change your page-> the function and the declaration of the Global Variable-> put the javascript function

    You must extract the rowid in the first place, for which you want to set the time, see line 2

    assuming f06, f07 and f08 is the id of the start date, and end date columns respectively, and duration

    See no line no 8 how set the value returned by the process of ajax at the duration column

    Replace your column to the respective column identifiers in the code below

    function f_calulate_duration(pThis) {
      var row_id  = pThis.id.substr(4);
      var start_date = $('#f06_'+row_id).val();
      apex.server.process ( "CALC_DURATION", {
      x01: start_date,x02: $(pThis).val()
    }, { success: function( pData ) {
    // set duration to duration column
    $('#f08_'+row_id).val(pData);
    // disable duration column
    $("#f08_" + row_id).attr("readonly", true).addClass('row_item_disabled'); }
    });
    }
    

    Step 4: choose the end date call the javascript function

    Go to report attributes-> edit your Date column end-> column-> Attrbiutes element attributes-> put the code below

    onchange="javascript:f_calulate_duration(this);"
    


    hope this helps you,

    Kind regards

    Jitendra

  • difference between two dates in the year/month/day in Obiee

    Hi gurus,

    I know this question have been asked and answered several times but I have a requirement that is a little different, then the previous ones.

    I want to calculate the difference between two dates in OBIEE10g in year/month/day format similar to the below SQL output

    SQL > select end_date, start_date,

    trunc (months_between (end_date, start_date) / 12) years.

    months of mod (trunc (months_between (end_date, start_date)), 12).

    End_date - add_months (start_date, trunc (months_between (end_date, start_date))) days

    t

    Thanks in advance

    SK

    Search for this

    "TIMESTAMPDIFF IN THE FORM OF MTHS # YEARS."

    or else

    To get the current mandate of employees since the date of hiring in the form of # years # mths or # year (s) # month (s)

    Concat (concat (cast (TIMESTAMPDIFF (SQL_TSI_Month, "Employee attributes". (((' ' Hiring last Date employee ", CURRENT_DATE) / 12 as char),"Year (s)"), concat (cast (MOD (TIMESTAMPDIFF (SQL_TSI_Month,"Employee attributes". (((((' ' Hiring last Date employee ", CURRENT_DATE), 12) as char), 'Month (s)'))

    Concat (concat (CAST (TIMESTAMPDIFF (SQL_TSI_YEAR, "Employee attributes". (((' ' Hiring last Date employee ", CURRENT_DATE) as CHAR),"Year (s)"), concat (cast (MOD (TIMESTAMPDIFF (SQL_TSI_Month,"Employee attributes". (((((' ' Hiring last Date employee ", CURRENT_DATE), 12) as char), 'Mth (s)'))

  • Number of Saturdays between two dates

    Hello

    How can I get number of Saturdays between two dates, including the two dates?

    for example number of Saturdays between 09/05/2014 and 10/05/2014 is five

    Help, please

    I use oracle 10g

    SQL> with t
      2  as
      3  (
      4  select to_date('05/09/2014 ', 'dd/mm/yyyy') from_dt
      5       , to_date('05/10/2014 ', 'dd/mm/yyyy') to_dt
      6    from dual
      7  )
      8   select to_char(from_dt + (level-1), 'fmDay') day_
      9        , count(*) cnt
     10     from t
     11  connect
     12       by level <= to_dt - from_dt + 1
     13    group
     14       by to_char(from_dt + (level-1), 'fmDay');
    
    DAY_             CNT
    --------- ----------
    Saturday           5
    Thursday           4
    Tuesday            4
    Friday             5
    Wednesday          4
    Monday             4
    Sunday             5
    
    7 rows selected.
    
    SQL>
    
  • Days between two dates given

    Hi all

    I need the days between two dates given.

    Select to_date('25-mar-2014','dd-mon-yyyy') start_date, end_date to_date('30-mar-2014','dd-mon-yyyy')

    of the double

    Desired output:

    25

    26

    27

    28

    29

    30

    Thanks in advance.

    Kind regards

    Afzal.

    Select the level - 1 desired_output + to_number (to_char (start_date, 'dd'))

    of (to_date('25-mar-2014','dd-mon-yyyy') select start_date, end_date to_date('30-mar-2014','dd-mon-yyyy'))

    of the double

    )

    connect by level<=  end_date="" -="" start_date="" +="">

    DESIRED_OUTPUT
    25
    26
    27
    28
    29
    30

    Concerning

    Etbin

  • Number of occurrences of a day between two dates

    Hello

    I have a requirement in my code to count the number of times per day occurs between two dates. So, for example if

    start date = January 1, 2014

    end date = March 31, 2014

    The number of times that happens day 1 is three times. That's why I want the result to be 3. My three input parameters are the number of the day, start and end dates. I know that this can be done by parsing through the days and incrementing a counter of sorts, but can it be done without any loop etc?

    Looking for options of

    Thank you

    Birdy

    SELECT COUNT (TO_CHAR (DAYS, 'DD')) IN)

    SELECT DAYS START_DATE + LEVEL 1

    FROM T1

    CONNECT BY LEVEL<=>

    WHERE TO_CHAR (DAYS, 'DD') ='&01';

    Post edited by: Parth272025

  • can we do vMotion between two data center

    Dear team,

    Can we do vMotion between two data center (esxi5, x)

    Can we do SVMotion between two data center (esxi5, x)

    Note: it is not a physical data center, it is a virtual data center

    can we do vMotion between clusters (esxi5.x)

    can we do SVMotion between clusters (esxi5.x)

    concerning

    Mr. VMware

    Can we do vMotion between two data center (esxi5, x)

    NO, you can't.

    Can we do SVMotion between two data center (esxi5, x)

    Yes, as long as data warehouses are shared.

    can we do vMotion between clusters (esxi5.x)

    Yes, as they perform the same CPU families.

    can we do SVMotion between clusters (esxi5.x)

    Yes, as long as data warehouses are shared.

  • How to find days between two dates in days

    Hi, I want to get the days between two dates, expressed in days, how can I do this?  For example, I date i.e. 1 October 10, 2013 (Thursday) and 2 as October 13, 2013 (Sunday).  How can I get a production of:

    Thursday, Friday, Saturday and Sunday, which are the days between Oct. 10-13, 2013.  I hope you understand my point.  Thank you

    You can try something like this

    CURSOR LOAD_PROF is

    SELECT load_prof1, v_time_profile_day

    OF load_profile_test

    WHERE profile_day IN (select TO_CHAR(:day1+level-1,'Day')

    of the double

    connect by level<>

    );

    Kind regards

    S Pax

  • Number of weeks between two dates that are in the same or different year

    Hello

    How to calculate the number of weeks between two dates?

    for example. "" "17-mar-2013' and June 27, 2013" or June 15, 2013 "and" 25-mar-2014


    Thanks in advance.

    lukx

    Hello

    Looks like your date range is incorrect.

    Please try the below.

    SQL >-front right

    SQL > select D2 - D1 "days."

    2 round ((D2-D1)/7.0) "weeks."

    3 round (Months_between (d1, d2), 0) 'months '.

    (select 4

    5 TO_DATE ('20121201', 'YYYYMMDD') D1, D2 TO_DATE ('20130116', 'YYYYMMDD')

    6 from two

    (7) date_range;

    Elapsed days weeks months

    ------------ --------- ---------

    46         7         1

  • Calculate the (age) years between two dates

    Nice day!

    I have not been able to find an answer, that I was able to use in the archives or online and would be very grateful for the help.  I'm working with Adobe Acrobat Pro XI (not LiveCycle) and I have very little experience with programming (for the most part, copy / paste).

    I need to create a text box that calculates the number of years between two dates entered, i.e. the age when the date of birth and death are given.  Also, would be nice if she was a Virgin until the two were provided.  Anyone would be able to give me the code I need to put in the custom calculation script?

    Once again, any help would be much appreciated!  Thank you and have a wonderful day!

    For the fields for Date of birth DOB and DOD for the Date of death and age in complete years both by using a'd-mmm-yyyy' date format you can use a custom calculation to the JavaScript for the field of age as:

    function GetField (cName) {}
    get the field with error trapping object;
    oField var = this.getField (cName);
    test error;
    if(oField == null) app.alert ("error during the" + cName, 1, 0);
    Returns the field object;
    return oField;
    } / / end GetField function;

    function {Scand (cFormat, cString)
    using date string format convert object date;
    convert string to date using format;
    Kai var = util.scand (cFormat, cString);
    the value null is an error of conversion;
    if(oDate == null) app.alert ("Conversion error" cString "by using the format" + cFormat, 1, 0);
    date of return;
    Return to oDate;
    } / / end Scand function;

    clear the value of the field;

    Event.Value ="";
    get data dob and dod;
    var oDOB = GetField ("DOB");
    Var o = GetField ("DOD");

    treat only if DOB and DOD have value and are not null;
    If (oDOB! = null & o! = null & oDOB.value! = "" & oDOD.value!) = "") {}

    convert the DOB and DOD to date objects.
    oDOB var = util.scand ("d-mmm-yyyy", oDOB.value);
    O var = util.scand ("d-mmm-yyyy", oDOD.value);

    get the difference over the years;
    var Age = oDOD.getFullYear () - oDOB.getFullYear ();

    adjust for month of previous DOD DOB;
    If (oDOD.GetMonth)< odob.getmonth())="">

    adjust the DOD before DOB date in the month of birth;

    If (oDOD.GetMonth () == oDOB.getMonth () & oDOD.getDate ())< odob.getdate())="">
    Set the value of the field;

    Event.Value = Age;
    }

  • JavaScript anomaly on the number of days between two dates

    Use ApEx 4.0, I found an anomaly in a javascript code that calculates the number of days between two dates, the current_date and the past_date. If the past and present is the or before March 10, 2013, and the current_date lies between 10 March 2013 and November 3, 2013, the number of days will be from 1 day to less than the actual number. Between November 3, 2013 and on 4 November 2013, the increments of number by 2, then the count will be accurate from this date forward.

    Here are some examples:

    March 10, 2013 = 69 days of December 31, 2012
    March 11, 2013 = 69 days of December 31, 2012
    March 12, 2013 = 70 days of December 31, 2012

    November 3, 2013 = 306 days in December 31, 2012
    November 4, 2013 = 308 days in December 31, 2012

    11 March should be 70 and 12 March should be 71. November 3 is 307 and 4 November corrects the number of fake, which began March 11.

    Change the past_date to March 10, 2013 produces the following:

    March 10, 2013 = 0 days of March 10, 2013
    March 11, 2013 = 0 days of March 10, 2013
    March 12, 2013 = 1 days of March 10, 2013

    But change the past_date to 11 March 2013, product of the correct numbers:

    March 11, 2013 = 0 days of March 11, 2013
    March 12, 2013 = 1 days of March 11, 2013
    March 13, 2013 = 2 days of March 11, 2013

    I would certainly all help to determine the cause of this anomaly. Here's the javascript code:

    var w1 = ($v ("P48_PAST_DATE"));
    W1 = (w1.toString ());
    vmon var = (w1.substr (3.3));
    vyr var = (w1.substr (7));
    var r = (vyr.length);
    If (r == 2)
    vyr. = (parseFloat (vyr) + 2000);
    vday var = (w1.substr (0.2));
    var y = (vmon.concat ("", vday, ",", vyr));
    y = Date.parse (y);

    var w2 = ($v ("P48_CURRENT_DATE"));
    var vmon2 = (w2.substr (3.3));
    var vyr2 = (w2.substr (7));
    var vday2 = (w2.substr (0.2));
    var x = (vmon2.concat ("", vday2, ",", vyr2));
    x = Date.parse (x);

    var numdays = (x - y);
    numdays = (Math.floor(numdays / 86400000));
    $s ("P48_NUMBEROFDAYS", numdays);

    Did you google for something like "javascript number of days between two dates. I think you will find the explanation to this observation:

    This method does not work correctly if there is an advanced economies jump between the two dates.

    There are examples available to calculate the difference between two dates.

Maybe you are looking for