Get the number of month, week and day between 2 dates

Hi all

Is it possible to display the number of months, weeks and days between 2 dates? by using only the SQL or PL/SQL...

Entry:
Date: October 1, 2010
Date: October 19, 2010

I want output like below (assuming starts the week from Monday to Sunday in oracle).

October 1, 2010-(since it's in the middle of the week)
October 2, 2010-(since it's in the middle of the week)
October 3, 2010-(since it's in the middle of the week)
40. (4 Oct-10 Oct falls into the 40th week of the year)
41. (11 Oct-17 Oct falls into the 41st week of the year)
October 18, 2010-(since it's in the middle of the week)
October 19, 2010-(since it's in the middle of the week)


Note: If there is a month between the date, the number of the month should be displayed.
End of the month, the remaining date included with a full week, then the week of the year number should
displayed. After posting the week, remaining dates should be displayed as it is...


Appreciate your help...



Thank you.
Fox.

You mean something like this...

SQL> ed
Wrote file afiedt.buf

  1  WITH t AS (select date '2010-09-27' as fdate, date '2010-11-21' as tdate from dual)
  2  --
  3  -- END OF TEST DATA
  4  --
  5  select dt2
  6  from (
  7        select dt,
  8               case when days_of_mn = days_in_month then 'Whole: '||to_char(dt,'Month')
  9                    when days_of_wk = 7 then 'Week: '||to_char(dt,'fmWW')
 10               else to_char(dt, 'DD-fmMonth-YYYY')
 11               end as dt2
 12              ,row_number() over (partition by
 13                 case when days_of_mn = days_in_month then to_char(dt,'Month')
 14                                  when days_of_wk = 7 then 'Week: '||to_char(dt,'fmWW')
 15                 else to_char(dt, 'DD-fmMonth-YYYY')
 16                 end order by dt) as rn
 17        from (
 18              select dt, wk, mn, days_in_month
 19                    ,count(*) over (partition by wk) as days_of_wk
 20                    ,count(*) over (partition by mn) as days_of_mn
 21              from (
 22                    select fdate+rownum-1 as dt
 23                          ,to_number(to_char(fdate+rownum-1,'fmWW')) as wk
 24                          ,to_number(to_char(fdate+rownum-1,'fmMM')) as mn
 25                          ,to_number(to_char(last_day(fdate+rownum-1),'fmDD')) as days_in_month
 26                    from t
 27                          connect by rownum <= tdate-fdate+1
 28                   )
 29             )
 30        ) x
 31  where rn = 1
 32* order by dt
SQL> /

DT2
-----------------
27-September-2010
28-September-2010
29-September-2010
30-September-2010
Whole: October
Week: 44
Week: 45
Week: 46
19-November-2010
20-November-2010
21-November-2010

11 rows selected.

SQL>

Tags: Database

Similar Questions

  • is there an easy way to get the number of months in a year in a date range?

    Hi, experts, I am a newbie.

    are there any easy ways to get the number of months in a year in a date range?

    I would like to write a user-defined function.

    the input parameters are startdate, enddate, year

    the output is a number, not a month.

    for example, case 1

    StartDate = 01032009 (DDMMYYYY)
    end date = 28022010 (DDMMYYYY)
    If the year 2009, the output is 10
    If the year = 2010, the output is 2

    case 2:

    StartDate = 10032009 (DDMMYYYY)
    end date = 15032010 (DDMMYYYY)
    If the year 2009, the output is 10
    If the year = 2010, the output is 3

    Thank you very much!

    Hello

    You can (also) try this:

    SQL> with s as (
      2  ------------ Sample data -------------
      3  select to_date('01032009','ddmmyyyy') startdt, to_date('28022010','ddmmyyyy') enddt, 2009 yr from dual
      4  union all
      5  select to_date('01032009','ddmmyyyy') startdt, to_date('28022010','ddmmyyyy') enddt, 2010 yr from dual
      6  union all
      7  select to_date('10032009','ddmmyyyy') startdt, to_date('15032010','ddmmyyyy') enddt, 2009 yr from dual
      8  union all
      9  select to_date('10032009','ddmmyyyy') startdt, to_date('15032010','ddmmyyyy') enddt, 2010 yr from dual
     10  ------------ Sample data -------------
     11  )
     12  select startdt, enddt, yr,
     13  months_between(
     14          least(trunc(to_date(yr+1,'yyyy'),'year') , add_months(trunc(enddt,'month'),1))
     15          , greatest(trunc(to_date(yr,'yyyy'),'year') , trunc(startdt,'month'))
     16  ) nbmonths
     17  from s;
    
    STARTDT    ENDDT              YR   NBMONTHS
    ---------- ---------- ---------- ----------
    01/03/2009 28/02/2010       2009         10
    01/03/2009 28/02/2010       2010          2
    10/03/2009 15/03/2010       2009         10
    10/03/2009 15/03/2010       2010          3
    

    It's pretty simple. (no connection with, without functions SQL only integrated multicast, etc...)

  • To find the months and days between 2 dates

    Hello

    I want to find the months and days between 2 dates.

    For example.

    1 - Date: August 25, 2013

    2 - Date: October 23, 2013

    If we consider each month 30 days, it should give

    August 25, 2013 to August 30, 2013 = 6 days

    01-Sep-2013-30-Sep-2013 = 1 month

    October 23, 2013 to October 30, 2013 = 8 days

    Total = 1 month and 14 days.

    Kindly help as soon as possible.

    Thanks and greetings

    Suresh

    Assuming that d2 > d1,.

    where d)

    Select sysdate d1, sysdate + 56 double d2

    Union all select to_date (March 1, 2013 ',' dd-mon-yyyy "") d1, to_date (March 31, 2013 ',' dd-mon-yyyy ') d2 double

    Union all select to_date (5 February 2013 ',' dd-mon-yyyy ') d1, to_date (March 31, 2013 ',' dd-mon-yyyy "") double d2

    Union all select to_date (February 25, 2013 ',' dd-mon-yyyy "") d1, to_date (March 23, 2013 ',' dd-mon-yyyy ') d2 double

    Union all select to_date (February 25, 2013 ',' dd-mon-yyyy ') d1, to_date (March 31, 2013 ',' dd-mon-yyyy "") double d2

    Union all select to_date (August 2, 2013 ',' dd-mon-yyyy "") d1, to_date (29 October 2013 ',' dd-mon-yyyy ') d2 double

    Union all select to_date (February 1, 2013 ',' dd-mon-yyyy "") d1, to_date (May 31, 2013 ',' dd-mon-yyyy ') d2 double

    Union all select to_date (25 August 2013 ',' dd-mon-yyyy "") d1, to_date ('03-Sep-2013', 'Mon-dd-yyyy') d2 double

    Union all select to_date (July 30, 2013 ',' dd-mon-yyyy "") d1, to_date (August 31, 2013 ',' dd-mon-yyyy ') d2 double

    Union all select to_date (July 31, 2013 ',' dd-mon-yyyy ') d1, to_date (August 30, 2013 ',' dd-mon-yyyy "") double d2

    Union all select to_date (July 31, 2013 ',' dd-mon-yyyy ') d1, to_date (3 August 2013 ',' dd-mon-yyyy "") double d2

    Union all select to_date (3 July 2013 ',' dd-mon-yyyy "") d1, to_date (August 31, 2013 ',' dd-mon-yyyy ') d2 double

    Union all select to_date ('31-08-2013', ' dd-mm-yyyy'), to_date('05-10-2013','dd-mm-yyyy') of the double

    Union all select to_date ('05-02-2013', ' dd-mm-yyyy'), to_date('31-03-2013','dd-mm-yyyy') of the double

    Union all select to_date ('05-02-2013', ' dd-mm-yyyy'), to_date('05-03-2013','dd-mm-yyyy') of the double

    Union all select to_date ('05-02-2013', ' dd-mm-yyyy'), to_date('05-02-2013','dd-mm-yyyy') of the double

    )

    Select d1, d2,

    1 + 30 * trunc (months_between (d2, d1)) + LESS (extract (day of d2), 30)-LESS (excerpt (d1 day), 30)

    + CASE when extracted (d2 day)< extract(day="" from="" d1)="" then="" 30="" else="" 0="" end ="">

    d

    D1 D2 DAYSBETWEEN

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

    October 10, 2013 5 December 2013 56

    March 1, 2013 30 March 31, 2013

    5 February 2013 March 31, 2013 56

    February 25, 2013 March 23, 2013 29

    February 25, 2013 March 31, 2013 36

    August 2, 2013 29 October 2013 88

    February 1, 2013 may 31, 2013 120

    August 25, 2013 03 - Sep-2013 9

    July 30, 2013 31 August 31, 2013

    July 31, 2013 August 30, 2013 31

    July 31, 2013 3 August 2013 4

    July 3, 2013 August 31, 2013 58

    31 August 2013 5 October 2013 36

    5 February 2013 March 31, 2013 56

    5 February 2013 March 5, 2013 31

    February 5, 2013 February 5, 2013 1

    In my view, which corresponds to your rules.

  • Select the number of months (NULL and non-null separated)

    -Table_1
    -------------

    create table_1
    (
    Arrival_Date DATE
    Counter_seq number (*) not null,
    Exclusion_type varchar2 (10)
    )

    -INSERTION
    -------------

    INSERT INTO 'DW_DOCA '. "' TABLE_1 ' ('ARRIVAL_DATE', 'COUNTER_SEQ', 'EXCLUSION_TYPE') VALUES (TO_DATE('12-DEC-2009', 'dd-Mon-yyyy HH:MI:SS AM'), 1,");
    INSERT INTO 'DW_DOCA '. "' TABLE_1 ' ('ARRIVAL_DATE', 'COUNTER_SEQ', 'EXCLUSION_TYPE') VALUES (TO_DATE('12-JAN-2010', 'dd-Mon-yyyy HH:MI:SS AM'), 2, 'PAW');
    INSERT INTO 'DW_DOCA '. "' TABLE_1 ' ('ARRIVAL_DATE', 'COUNTER_SEQ', 'EXCLUSION_TYPE') VALUES (TO_DATE('28-DEC-2009', 'dd-Mon-yyyy HH:MI:SS AM'), 3, 'HAN');
    INSERT INTO 'DW_DOCA '. "' TABLE_1 ' ('ARRIVAL_DATE', 'COUNTER_SEQ', 'EXCLUSION_TYPE') VALUES (TO_DATE('12-FEB-2010', 'dd-Mon-yyyy HH:MI:SS AM'), 4,");
    INSERT INTO 'DW_DOCA '. "' TABLE_1 ' ('ARRIVAL_DATE', 'COUNTER_SEQ', 'EXCLUSION_TYPE') VALUES (TO_DATE('12-JAN-2010', 'dd-Mon-yyyy HH:MI:SS AM'), 5,"LUG");
    INSERT INTO 'DW_DOCA '. "' TABLE_1 ' ('ARRIVAL_DATE', 'COUNTER_SEQ', 'EXCLUSION_TYPE') VALUES (TO_DATE('28-JAN-2009', 'dd-Mon-yyyy HH:MI:SS AM'), 6, 'HAN');
    INSERT INTO 'DW_DOCA '. "' TABLE_1 ' ('ARRIVAL_DATE', 'COUNTER_SEQ', 'EXCLUSION_TYPE') VALUES (TO_DATE('12-DEC-2009', 'dd-Mon-yyyy HH:MI:SS AM'), 7,");
    INSERT INTO 'DW_DOCA '. "' TABLE_1 ' ('ARRIVAL_DATE', 'COUNTER_SEQ', 'EXCLUSION_TYPE') VALUES (TO_DATE('12-FEB-2010', 'dd-Mon-yyyy HH:MI:SS AM'), 8, 'PAW');
    INSERT INTO 'DW_DOCA '. "' TABLE_1 ' ('ARRIVAL_DATE', 'COUNTER_SEQ', 'EXCLUSION_TYPE') VALUES (TO_DATE('28-JAN-2010', 'dd-Mon-yyyy HH:MI:SS AM'), 9, 'HAN');
    INSERT INTO 'DW_DOCA '. "' TABLE_1 ' ('ARRIVAL_DATE', 'COUNTER_SEQ', 'EXCLUSION_TYPE') VALUES (TO_DATE('12-FEB-2010', 'dd-Mon-yyyy HH:MI:SS AM'), 10,");
    INSERT INTO 'DW_DOCA '. "' TABLE_1 ' ('ARRIVAL_DATE', 'COUNTER_SEQ', 'EXCLUSION_TYPE') VALUES (TO_DATE('12-DEC-2010', 'dd-Mon-yyyy HH:MI:SS AM'), 11, 'PAW');
    INSERT INTO 'DW_DOCA '. "' TABLE_1 ' ('ARRIVAL_DATE', 'COUNTER_SEQ', 'EXCLUSION_TYPE') VALUES (TO_DATE('28-JAN-2010', 'dd-Mon-yyyy HH:MI:SS AM'), 12, 'HAN');
    INSERT INTO 'DW_DOCA '. "' TABLE_1 ' ('ARRIVAL_DATE', 'COUNTER_SEQ', 'EXCLUSION_TYPE') VALUES (TO_DATE('12-DEC-2009', 'dd-Mon-yyyy HH:MI:SS AM'), 13,");
    INSERT INTO 'DW_DOCA '. "' TABLE_1 ' ('ARRIVAL_DATE', 'COUNTER_SEQ', 'EXCLUSION_TYPE') VALUES (TO_DATE('12-FEB-2010', 'dd-Mon-yyyy HH:MI:SS AM'), 14,"LUG");
    INSERT INTO 'DW_DOCA '. "' TABLE_1 ' ('ARRIVAL_DATE', 'COUNTER_SEQ', 'EXCLUSION_TYPE') VALUES (TO_DATE('28-JAN-2010', 'dd-Mon-yyyy HH:MI:SS AM'), 15,");
    INSERT INTO 'DW_DOCA '. "' TABLE_1 ' ('ARRIVAL_DATE', 'COUNTER_SEQ', 'EXCLUSION_TYPE') VALUES (TO_DATE('12-FEB-2010', 'dd-Mon-yyyy HH:MI:SS AM'), 16,"LUG");
    INSERT INTO 'DW_DOCA '. "' TABLE_1 ' ('ARRIVAL_DATE', 'COUNTER_SEQ', 'EXCLUSION_TYPE') VALUES (TO_DATE('12-JAN-2010', 'dd-Mon-yyyy HH:MI:SS AM'), 17,");
    INSERT INTO 'DW_DOCA '. "' TABLE_1 ' ('ARRIVAL_DATE', 'COUNTER_SEQ', 'EXCLUSION_TYPE') VALUES (TO_DATE('28-JAN-2010', 'dd-Mon-yyyy HH:MI:SS AM'), 18,");
    INSERT INTO 'DW_DOCA '. "' TABLE_1 ' ('ARRIVAL_DATE', 'COUNTER_SEQ', 'EXCLUSION_TYPE') VALUES (TO_DATE('12-DEC-2009', 'dd-Mon-yyyy HH:MI:SS AM'), 19, 'HAN');
    INSERT INTO 'DW_DOCA '. "' TABLE_1 ' ('ARRIVAL_DATE', 'COUNTER_SEQ', 'EXCLUSION_TYPE') VALUES (TO_DATE('12-DEC-2009', 'dd-Mon-yyyy HH:MI:SS AM'), 20,");
    INSERT INTO 'DW_DOCA '. "' TABLE_1 ' ('ARRIVAL_DATE', 'COUNTER_SEQ', 'EXCLUSION_TYPE') VALUES (TO_DATE('28-FEB-2010', 'dd-Mon-yyyy HH:MI:SS AM'), 21,"LUG");
    INSERT INTO 'DW_DOCA '. "' TABLE_1 ' ('ARRIVAL_DATE', 'COUNTER_SEQ', 'EXCLUSION_TYPE') VALUES (TO_DATE('12-JAN-2010', 'dd-Mon-yyyy HH:MI:SS AM'), 22,"LUG");
    INSERT INTO 'DW_DOCA '. "' TABLE_1 ' ('ARRIVAL_DATE', 'COUNTER_SEQ', 'EXCLUSION_TYPE') VALUES (TO_DATE('12-DEC-2009', 'dd-Mon-yyyy HH:MI:SS AM'), 23,"HAN");
    INSERT INTO 'DW_DOCA '. "' TABLE_1 ' ('ARRIVAL_DATE', 'COUNTER_SEQ', 'EXCLUSION_TYPE') VALUES (TO_DATE('28-JAN-2010', 'dd-Mon-yyyy HH:MI:SS AM'), 24,");
    INSERT INTO 'DW_DOCA '. "' TABLE_1 ' ('ARRIVAL_DATE', 'COUNTER_SEQ', 'EXCLUSION_TYPE') VALUES (TO_DATE('12-FEB-2010', 'dd-Mon-yyyy HH:MI:SS AM'), 25,");
    INSERT INTO 'DW_DOCA '. "' TABLE_1 ' ('ARRIVAL_DATE', 'COUNTER_SEQ', 'EXCLUSION_TYPE') VALUES (TO_DATE('28-DEC-2010', 'dd-Mon-yyyy HH:MI:SS AM'), 26,"LUG");
    INSERT INTO 'DW_DOCA '. "' TABLE_1 ' ('ARRIVAL_DATE', 'COUNTER_SEQ', 'EXCLUSION_TYPE') VALUES (TO_DATE('12-FEB-2010', 'dd-Mon-yyyy HH:MI:SS AM'), 27,");


    -SELECT THE NUMBER OF MONTHS
    --------------------------------------

    SELECT EXCLUSION_TYPE,
    County (decode (to_char (ARRIVAL_DATE, 'MON-YYYY'), "DEC-2009", COUNTER_SEQ ")) dec09,.
    County (decode (to_char (ARRIVAL_DATE, ' MON-YYYY ""), "JAN-2010", COUNTER_SEQ ")) Jan10.
    County (decode (to_char (ARRIVAL_DATE, 'MON-YYYY'), ' Feb-2010 ", COUNTER_SEQ")) Feb10
    FROM TABLE_1
    EXCLUSION_TYPE GROUP;


    -CHOOSE IT ABOVE RETURENS: -.
    ------------------------------------------------


    EXCLUSION_ DEC09 JAN10 FEV10
    4 4 4
    0 3 4 LEG
    HAN 3 2 0


    My question is, I need to select a month ruturning one row of NULL values and a line of values not null. Like that so all right: -.

    EXCLUSION_ DEC09 JAN10 FEV10
    Exclusion_Type 4 4 4 NULL
    Exclusion_Type Not null 3 5 4

    The ideas people?

    Published by: Deeds_2001 on November 16, 2010 12:47 AM
    SQL> SELECT DECODE(exclusion_type,NULL,'NULL','NOT NULL') exclusion_type,
      2  COUNT(DECODE(TO_CHAR(arrival_date, 'MON-YYYY'), 'DEC-2009', counter_seq)) Dec09,
      3  COUNT(DECODE(TO_CHAR(arrival_date, 'MON-YYYY'), 'JAN-2010', counter_seq)) Jan10,
      4  COUNT(DECODE(TO_CHAR(arrival_date, 'MON-YYYY'), 'FEB-2010', counter_seq)) Feb10
      5  FROM table_1
      6  GROUP BY DECODE(exclusion_type,NULL,'NULL','NOT NULL');
    
    EXCLUSIO      DEC09      JAN10      FEB10
    -------- ---------- ---------- ----------
    NULL              4          4          4
    NOT NULL          3          5          4
    
    SQL> 
    
  • 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

  • Get the number of months between the dates.

    Hi I need to get the exact number of months between the dates. So if I'm Sysdate - to_date(31-JAN-2011) I should get something like 8.4 months. Months_between function doesn't quite give me what I need. Is it possible that I can do this?

    876056 wrote:
    Hi I need to get the exact number of months between the dates. So if I'm Sysdate - to_date(31-JAN-2011) I should get something like 8.4 months. Months_between function doesn't quite give me what I need. Is it possible that I can do this?

    I don't see how you get 8.4 months. The counted months are February, March, April, may, June, July, August and, as of today, 9 and change the days of September. Unless I forgot the lessons of counting, I learned in kndergarten is 7 full months and a bit.

    Maybe you want something like:

    SQL> select months_between(Sysdate, to_date('01-JAN-2011', 'dd-mon-yyyy')) mb,
      2         (Sysdate - to_date('01-JAN-2011', 'dd-mon-yyyy'))/30 div30
      3  from dual;
    
            MB      DIV30
    ---------- ----------
    8.27800142 8.38726813
    

    If you get the form date a table, you can use trunc (date_column, 'mm') at the date of the first day of the month.

    John

  • Gets the number of months to a Date

    Hello

    I use the version of database Oracle 11.2.1. I would like to calculate the number of fiscal month of a date.

    For example:

    Date: 31/03/2013
    Fiscal No. month: 12

    The fiscal year runs from 01 - Apr-31 - March each year.

    Hello

    You can use

    EXTRACT (MONTH FROM (ADD_MONTHS (mydate, -3)))
    

    Example:

    WITH mytable AS (    SELECT TRUNC(SYSDATE) - 400 + LEVEL mydate
                           FROM DUAL
                     CONNECT BY LEVEL <= 400)
    SELECT mydate, EXTRACT (MONTH FROM (ADD_MONTHS (mydate, -3))) fiscal_month
      FROM mytable
     WHERE mydate = TRUNC (mydate, 'MM')
        OR mydate = LAST_DAY(mydate);
    
    MYDATE    FISCAL_MONTH
    --------- ------------
    31-MAR-12           12
    01-APR-12            1
    30-APR-12            1
    01-MAY-12            2
    31-MAY-12            2
    01-JUN-12            3
    30-JUN-12            3
    01-JUL-12            4
    31-JUL-12            4
    01-AUG-12            5
    31-AUG-12            5
    01-SEP-12            6
    30-SEP-12            6
    01-OCT-12            7
    31-OCT-12            7
    01-NOV-12            8
    30-NOV-12            8
    01-DEC-12            9
    31-DEC-12            9
    01-JAN-13           10
    31-JAN-13           10
    01-FEB-13           11
    28-FEB-13           11
    01-MAR-13           12
    31-MAR-13           12
    01-APR-13            1
    

    Kind regards.
    Al

  • Figure out how many years and days between two dates

    Nice day

    I've been dealing with the problem for a few days now so I thought that I could send it and see if someone can tell me what I'm doing wrong.

    / * Create a Date with a date object. */

    var d1 = getField "(RELEASE. DATE') .value;

    / * Create a date object containing the current date. */

    var d2 = getField("Text4").value;

    / * Number of years difference. */

    diff = (((d2.valueOf () - d1.valueOf (()) / 1000) / 60) / 60) / 24) / 365;

    Displays the field "Text3".

    getField("Text3").value = (diff); & #8232;
    < END >

    RELEASE. Value DATE is January 1, 2011, with a date format dd/mmm/yyyy

    Text4 value is March 1, 2011 with a date format dd/mmm/yyyy

    The release of Text3 gives me a 'NaN' result

    What I'm trying to do is calculated the number of years an employee has had with the company, and then display a balance of days that he had.

    Any thoughts would be greatly appreciated.

    repeated conversion from date string and number of days for the reuse of code
    function Date2Num (cFormat, cDate) {}
    Converts a date string formatted in days since the date of the time
    Kai var = util.scand (cFormat, cDate);
    Math.floor (oDate.getTime (return) / (1000 * 60 * 60 * 24));
    }

    / * Create a Date with a date object. */
    var d1 = (getField("Enrol_Day").value + "/" + getField("EnrolMonth").value + "/" + getField("EnrolYear").value);
    Converts a date in the date object string
    oD1 var = util.scand ("dd/mmm/yyyy", d1);
    get the current date of the field
    var d2 = (getField ("TD. RelDay") .value + ' / ' + getField ("TD. RelMonth") .value + ' / ' + getField ("TD. (RelYear') .value);

    calculate the difference in days
    diff var = Date2Num ("dd/mmm/yyyy", d2) - Date2Num ("dd/mmm/yyyy", d1);
    increment the value if the end date should be included in the calculation
    diff ++;
    convert days to truncate all years - to the next intiger lowest
    var carnavalSVP = Math.floor(diff / 365.25);
    get the current year interval - rest of diff days divided by 365.25 days
    var nDays = Math.floor (diff % 365.25);

    display the entered values
    CMSG var = ' end date: "+ d2 +" \t Compute days: ' "+ Date2Num (" dd/mmm/yyyy", d2);
    CMSG += "\nStart date:" + d1 + "\t Compute days: '" + Date2Num ("dd/mmm/yyyy", d1);
    Total difference in days
    CMSG += "\nTotal elapsed days:"+ diff;»
    result in years and days
    CMSG += "\nYears:" + carnavalSVP + "and" + nDays + 'days'; "."
    App.Alert (GSMC, 1, 0, "results");
    //

  • How to get the number of months missing

    I created a view as follows:

    CREATE OR REPLACE FORCE VIEW 'Vinfection1' ('MONTH', 'COUNT') AS
    Select 'MONTHS', 'COUNT' in)
    Select to_char(s.pdate,'Mon-yyyy') in the month, count (*) County
    of s surproc, diagnosis_surproc d
    where s.surprocid = d.surprocid and d.diagnosisid in ('506 ', ' 507', '508 ","509", ' 510')
    Group of to_char(pdate,'Mon-yyyy'))
    order of to_date(month,'Mon-yyyy')
    /

    A few months are missing from the view. I want to put this month and 0 in the view. How to do?

    Thank you
    Jennifer

    can be like that...

    select      to_char(s.pdate,'Mon-yyyy') as month,
         sum(case when d.diagnosisid in ('506', '507', '508', '509', '510') then 1 ELSE 0 END) as count
    from surproc s, diagnosis_surproc d
    where s.surprocid = d.surprocid
    group by to_char(pdate,'Mon-yyyy')
    

    HTH...

    Thank you...

  • Get the number of the month

    DB version: 10 gr 2

    I was asked to give a slow query performance.

    I think that he is trying to get the number of months (as of June 6, July 7) after a few months to add logic. I replaced the column date with sysdate.

    The query looks like
    SELECT TO_NUMBER(TO_CHAR(ADD_MONTHS(TO_DATE('01-'||TO_CHAR(sysdate,'MON-RRRR'),'DD-MON-RRRR'),3),'MM')) from dual
    Is there room for improvement?

    Hello

    What is

    select EXTRACT(MONTH FROM sysdate) from dual;
    

    Concerning
    Peter

  • Count of the number of months with unpaid for the last six months

    Hello

    I now table to store the daily presence of each employee

    ATTENDANCESHEET

    EMPID

    PAYROLLDATE

    UNPAID

    1

    10/01/2013

    6

    1

    10/02/2013

    2

    1

    11/01/2013

    0

    1

    11/02/2013

    0

    1

    12/01/2013

    0

    1

    12/02/2013

    0

    1

    01/01/2014

    0

    1

    01/02/2014

    0

    1

    02/01/2014

    0

    1

    02/02/2014

    0

    1

    03/01/2014

    45

    1

    03/02/2014

    0

    2

    03/01/2014

    0

    2

    03/02/2014

    0

    I want to get the number of months used unpaid in the past 6 months (excluding the current).

    If the month of payroll, I'm in treatment is 4, 2014, I spend 4 as payrollmonth and 2014 as payroll year

    The application must check the latest 6 month data and number of months for which there is any unpaid value

    In the case above for month 4, 2014, the power required is

    EmpID

    County

    1

    2

    2

    0

    I use oracle 10g

    EXAMPLES OF DATA

    create the table attendancesheet as

    (

    Select 1 as empid, to_date (January 10, 2013 ',' DD/MM/YYYY ') as payrolldate, 6 paid by union double all the

    Select 1 as empid, to_date (10 February 2013 ',' DD/MM/YYYY ') as payrolldate, 0 paid by union double all the

    Select 1 as empid, to_date (January 11, 2013 ',' DD/MM/YYYY ') as payrolldate, 0 paid by union double all the

    Select 1 as empid, to_date (February 11, 2013 ',' DD/MM/YYYY ') as payrolldate, 0 paid by union double all the

    Select 1 as empid, to_date (12 January 2013 ',' DD/MM/YYYY ') as payrolldate, 0 paid by union double all the

    Select 1 as empid, to_date (February 12, 2013 ',' DD/MM/YYYY ') as payrolldate, 0 paid by union double all the

    Select 1 as empid, to_date (1 January 2014 ',' DD/MM/YYYY ') as payrolldate, 0 paid by union double all the

    Select 1 as empid, to_date (February 1, 2014 ',' DD/MM/YYYY ') as payrolldate, 0 paid by union double all the

    Select 1 as empid, to_date (January 2, 2014 ',' DD/MM/YYYY ') as payrolldate, 0 paid by union double all the

    Select 1 as empid, to_date (February 2, 2014 ',' DD/MM/YYYY ') as payrolldate, 0 paid by union double all the

    Select 1 as empid, to_date (3 January 2014 ',' DD/MM/YYYY ') as payrolldate, 45 paid by union double all the

    Select 1 as empid, to_date (3 February 2014 ',' DD/MM/YYYY ') as payrolldate, 0 paid by union double all the

    Select 2 as empid, to_date (3 January 2014 ',' DD/MM/YYYY ') as payrolldate, 0 as default all the double union

    Select 2 as empid, to_date (3 February 2014 ',' DD/MM/YYYY ') as payrolldate, 0 paid double

    );

    Help, please

    Hello

    So, you want to count the distinct months for 6 months before (not included) the given month; is this fair?

    Here's one way:

    VARIABLE month VARCHAR2 (2)

    Year VARIABLE VARCHAR2 (4)

    EXEC: months: = '4';

    EXEC: year: "2014"; =

    WITH got_end_date AS

    (

    SELECT TO_DATE (: month |) '/' || : year

    , ' MM/YYYY ".

    ) AS end_date

    OF the double

    )

    SELECT a.empid

    , COUNT (DISTINCT

    CASE

    WHEN a.unpaid > 0

    THEN TRUNC (a.payrolldate, 'MONTH')

    END

    ), Cnt

    Of attendancesheet one

    JOIN e-got_end_date WE a.payrolldate > = ADD_MONTHS (e.end_date-6)

    AND a.payrolldate< >

    GROUP BY a.empid

    ORDER BY a.empid

    ;

    If you use a WHERE clause to exclude the lines with some outstanding = 0 (or unpaid is NULL), then you would get no output for employees like empid = 2 in this example.  A WHERE clause ignores an entire line, so I used an expression BOX just a value.

  • Get the number of days in a month based on the month and year of fields

    I have a column in my form which lists the days in a month. I want to configure a hidden field that calculates the total number of days in a month, based on the month and year of the field inputs. The number of days will determine what appears on the column. For example, if I put 4 months, and 2016 in the field of the year, I get 30 in the hidden field. Thus, on the column 'Day', I'll have numbers 1-30. Or if I put 2 months and 2016 in the field of the year, I get the 29 in the hidden field. If the numbers 1-29 appears in the column 'day '.

    Found this on some forum javascript code:

    //Month is 1 based
    function daysInMonth(month,year) {
      
    return new Date(year, month, 0).getDate();
    }

    //July
    daysInMonth
    (7,2009); //31
    //February
    daysInMonth
    (2,2009); //28
    daysInMonth
    (2,2008); //29

    I do not know how to convert this code in JavaScript to adobe and don't really know how to use it. All I know how to do is to configure the field values for the field month and year as variables. I am a novice programmer and would appreciate it really all the help I can get. Thank you in advance!

    The code seems to be JavaScript and runs as needed by using the JavaScript console.

    I would like to consider making more general code, so if you have a date string that includes at least the month and year we could just call the function and get the number of days for that month.

    The following script will calculate the number of days in a month, by using at least the month and year values can display the result on the JavaScript console and all of the value field for the field that has this code as the custom calculation Script.

    function daysInMonth (oDate) {}
    return new Date (oDate.getFullYear (), oDate.getMonth () + 1, 0) .getDate ();
    }

    nMonth var = this.getField("Month").valueAsString; get the value of month;
    nYear var = this.getField("Year").valueAsString; get the value of the year;

    Event.Value = "";

    If (nMonth! = "" & nYear!) = "") {}
    var MyDate = util.scand ("' / mm/yyyy ', nMonth +" / "+ nYear); convert to date object;
    var nDaysInMonth = daysInMonth (MyDate); get the number of days;

    Console.Open (); Open the JavaScript console;

    Console.clear(); clear the console;

    Console.println ("Days in" + nMonth + ":" + nDaysInMonth); show days in month;

    Event.Value = nDaysInMonth; Set the value of the field;

    }

  • Get the number of days, months and year

    Hi all

    I'm using OBIEE 11 g. I have a line of dash for year (2010, 2011, etc.) and months (Jan, Feb,..., Dec). How can I get the number of days in a given month and year in my report?

    For example, if I choose to Jan & 2011, I'd get 31 and 356. And if I choose Feb & 2011, I would get 28 and 356.

    Thank you!

    I have something more good option here... Try to use this

    DAYOFMONTH (TIMESTAMPADD (SQL_TSI_DAY, DAYOFMONTH (CURRENT_DATE) *-1, TIMESTAMPADD (SQL_TSI_MONTH, 1, CURRENT_DATE)))

    This will give you the days for the month in progress (Oct 2011) after calculating the last day of each month... Similary dynamically pass the value Date or month... You will need to modify this function but shud be simple. Hope this helps :)

  • get the number of the day of the week - any national locale is used

    Hi all

    My need is to get the number of the day of the week - any national local is used.

    For example, Saturday's 6th day of the week in my country, because the week starts on Monday.

    I heard that some countries start the week of Sunday.

    So my need is to compile code that does not depend on local national.

    How can I make it?

    Oracle Database 11 g Enterprise Edition Release 11.2.0.1.0 - 64 bit Production

    PL/SQL Release 11.2.0.1.0 - Production

    "CORE 11.2.0.1.0 Production."

    AMT for Linux: Version 11.2.0.1.0 - Production

    NLSRTL Version 11.2.0.1.0 - Production

    Hello

    2621671 wrote:

    Hi all

    My need is to get the number of the day of the week - any national local is used.

    For example, Saturday's 6th day of the week in my country, because the week starts on Monday.

    ...

    That's what you asked for, whatever your NLS settings:

    1 + TRUNC (dt) - TRUNC (dt, 'IW')

    If dt is a DATE, TRUNC (dt, 'IW') is the beginning of the ISO week containing dt.  ISO weeks always start on Monday, whatever NLS_TERRITORY, or other NLS parameters.

    I heard that some countries start the week of Sunday.

    So my need is to compile code that does not depend on local national.

    How can I make it?

  • get the number of days of the week to sysdate

    Hi all

    my need is to get the number of the day of the week of sysdate.

    Here's how can I make it right now:

    Select to_char(sysdate,'Dy') t1 double

    But he returns the abbreviated name of the day of the week while I need number of days of the week.

    Please help me. Thanks in advance.

    Best regards

    --

    Marco

    Or if you want the ISO week (Monday = day 1):

    Select trunc (sysdate) - trunc(sysdate,'IW') + 1 double;

Maybe you are looking for

  • Satellite M40-184: how to connect a projector?

    How can I connect to a projector? Thanks in advance

  • HP Envy 15-j030eb additional SSD

    Hello I have a laptop HP Envy 15 j030eb (product number: E4N79EA). I was wondering if the laptop had an additional location for one SSD (on the top of the 1 TB drive HARD is already)? I think remember me reading that it only supports a 24 GB SSD. Now

  • Canon 5 d Mark III. Images disappear

    Canon 5 d Mark III. Pictures on the camera screen but shows show CF card to be empty when it is connected to the computer. Used two CF cards different, same result. I have tried Sandisk Rescue program but no current images were found. Images counter

  • no available color for fonts when using hotmail

    When I need color for text when writing emails it does'nt work why £

  • Requirement of minimal operating system API

    Hi all, I have a n00bish question! In the API document, she said "since the BlackBerry API 6.0.0" does that mean that it only works for BlackBerry with OS 6.0.0 or older? Or again, it will work on OS 5.0.0 and down as well?