How to get days and months when two dates are given

Hi All,
I have a requirement where I need to return the number of months and days between given dates.
I dont need to take the year into account as the dates difference is always less than an year
I have 28-jun-2012 and 31-jan-2013 as dates.
I'm working on 10g
when I do select months_between(:a,:b) from dual and provide those dates it gives me 7.09677
I want it to give as 7 months and 9 days or what ever the exact days are.
Your inputs are much appreciated

BluShadow wrote:
874719 wrote:
Thanks a lot,BluShadow for your answer and would you mind giving it for the year as well like 0 years 7 months 3 days?Your original post said:
I dont need to take the year into account as the dates difference is always less than an yearNow you've got the idea, why not have a go yourself first, and then if you're still not getting it, post what you've tried so we can help you.Oh... go on... I'm in a good mood today...
SQL> ed
Wrote file afiedt.buf
  1  with t as (select date '2012-06-28' as start_date, date '2013-01-31' as end_date from dual union all
  2             select date '2012-02-29', date '2012-06-30' from dual union all
  3             select date '2010-02-28', date '2012-06-30' from dual union all
  4             select date '2012-02-29', date '2012-06-15' from dual
  5            )
  6  --
  7  select start_date, end_date
  8        ,months_between(end_date,start_date) as mnth_bet
  9        ,floor(months_between(end_date,start_date)/12) as yr
10        ,floor(mod(months_between(end_date,start_date),12)) as mnth
11        ,case when to_number(to_char(end_date,'DD')) >= to_number(to_char(start_date,'DD')) then
12           to_number(to_char(end_date,'DD')) - to_number(to_char(start_date,'DD'))
13         else
14           (to_number(to_char(last_day(start_date),'DD'))-to_number(to_char(start_date,'DD')))+
15           (to_number(to_char(end_date,'DD')))
16         end as dys
17* from t
SQL> /
START_DATE           END_DATE               MNTH_BET         YR       MNTH        DYS
28-JUN-2012 00:00:00 31-JAN-2013 00:00:00 7.09677419          0          7          3
29-FEB-2012 00:00:00 30-JUN-2012 00:00:00          4          0          4          1
28-FEB-2010 00:00:00 30-JUN-2012 00:00:00         28          2          4          2
29-FEB-2012 00:00:00 15-JUN-2012 00:00:00  3.5483871          0          3         15

Similar Messages

  • How to get Manager id automatically when Employee Id is given.

    How to get Manager id automatically when Employee Id is given.
    1) I created a simple BO with two elements namely
        1.Employee Id
        2.Manager id
    How to get employee's first name and last name?
    And how will i get manager id  automatic when i click employee id in element field.
    Anbu.

    Have you tried to use "APPS.FND_CONCURRENT" API?
    http://etrm.oracle.com/pls/trm11510/etrm_pnav.show_object?c_name=FND_CONCURRENT&c_owner=APPS&c_type=PACKAGE
    http://etrm.oracle.com/pls/trm11510/etrm_pnav.show_object?c_name=FND_CONCURRENT&c_owner=APPS&c_type=PACKAGE%20BODY
    Thanks,
    Hussein

  • How to Get days of Month in SSRS

    How can I get days of Month in SSRS report...?

    Hi RedZinc,
    You can do it by writing a SQL query to generate days of month. For doing recursive to generate days,
    Use CTE with recursive logic:
    Declare @StartDate as DATE, @EndDate as DATE;
    SET @StartDate = CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(GETDATE())-1),GETDATE()),101)
    SET @EndDate = CONVERT(VARCHAR(25),DATEADD(dd,-(DAY(DATEADD(mm,1,Getdate()))),DATEADD(mm,1,Getdate())),101)
     ;WITH cte AS (
                   SELECT @StartDate AS myDate
                   UNION ALL
                   SELECT DATEADD(Day,1,myDate)
                   FROM cte
                   WHERE DATEADD(Day,1,myDate) <=  @EndDate
      Select * from CTEtested the above sql code and it is working. CTE will be easy to implement recursive stuff.
    Maruthi... http://www.msbimaru.blogspot.com/

  • 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}

  • How to get  day if we give the date

    i want the day for tghis date(16-march-2006), how to get that
    select to_char(sysdate,'day') from dual,it gives the correct day but select to_char('16-mar-06','day') from dual it gives error,
    so how to get that day

    Hi
    First convert it '16-MAR-06' to date then give format
    select to_char(to_date('16-MAR-06','DD-MON-YY'),'day') from dual;
    TO_CHAR(T
    thursday
    Khuram Siddiqui
    [email protected]

  • How to get the difference between these two dates

    Hello Friends,
    I need to get the difference between these two fields which store dates but with varchar2 data types
    SELECT pac.segment1, pac.segment2 emp_no, pac.segment3 NAME,
    pac.segment4 POSITION, pac.segment5 start_date, pac.segment6,
    pac.segment7
    FROM per_analysis_criteria pac, fnd_id_flex_structures_vl ffs
    WHERE ffs.id_flex_structure_code = 'Employee Rejoin'
    AND ffs.id_flex_num = pac.id_flex_num
    AND TO_CHAR (TO_DATE (pac.segment7, 'YYYY/MM/DD HH24:MI:SS'))
    - TO_CHAR (TO_DATE (pac.segment6, 'YYYY/MM/DD HH24:MI:SS')) > 1;
    my query is something like this...
    am trying to find the difference between the last two columns but with not much luck..
    can some one suggest me a solution please

    SELECT pac.segment1, pac.segment2 person_id, pac.segment3 NAME,
    papf.employee_number, paaf.supervisor_id, pac.segment4 POSITION,
    pac.segment5 start_date, pac.segment6, pac.segment7,
    papf2.email_address,
    ( TO_DATE (TO_CHAR (pac.segment7), 'DD-MON-YYYY HH:MI:SS AM')
    - TO_DATE (pac.segment6, 'DD-MON-YYYY HH:MI:SS AM')
    + 1
    ) difference,
    POST.email_address
    FROM per_analysis_criteria pac,
    apps.fnd_id_flex_structures_vl ffs,
    per_all_people_f papf,
    per_all_assignments_f paaf,
    per_all_people_f papf2,
    (SELECT email_address, person_id
    FROM per_all_people_f
    WHERE person_id IN (
    SELECT person_id
    FROM per_all_assignments_f
    WHERE position_id IN (SELECT position_id
    FROM per_positions
    WHERE NAME LIKE 'HR Manager.704.')
    AND TRUNC (SYSDATE) BETWEEN effective_start_date
    AND effective_end_date)
    AND TRUNC (SYSDATE) BETWEEN effective_start_date AND effective_end_date
    AND business_group_id = fnd_profile.VALUE ('PER_BUSINESS_GROUP_ID')) POST
    WHERE ffs.id_flex_structure_code = 'Employee Rejoin'
    AND TO_CHAR (papf.person_id) = pac.segment2
    AND ffs.id_flex_num = pac.id_flex_num
    AND TRUNC (SYSDATE) BETWEEN papf.effective_start_date
    AND papf.effective_end_date
    AND papf.current_employee_flag = 'Y'
    AND papf.person_id = paaf.person_id
    AND TRUNC (SYSDATE) BETWEEN paaf.effective_start_date
    AND paaf.effective_end_date
    AND papf.person_id = paaf.person_id
    AND papf2.person_id = paaf.supervisor_id
    AND paaf.primary_flag = 'Y'
    AND TRUNC (SYSDATE) BETWEEN papf2.effective_start_date
    AND papf2.effective_end_date
    AND papf2.current_employee_flag = 'Y'
    and ( TO_DATE(to_char(pac.segment7), 'DD-MON-YYYY HH:MI:SS AM')-TO_DATE (pac.segment6, 'DD-MON-YYYY HH:MI:SS AM')+1) >1
    last line is giving me the error pls suggest a solution

  • How to get previous 2 months from current date in a dropdown?

    Hello Experts ,
                           In the application which I am developing, there is a requirement wherein , I want to Populate current month and previous two month in a drop down depending upon today's date. please help.
    Thanks & Regards,
    Pratbha Shukla

    The internal format for dates is yyyymmdd.  Therefore you can just grab the month value from the date:
    data lv_month type FCMNR.
    lv_month = lv_date+4(2).
    Just subtract from the month to get the two previous.
    data lv_previous1 type FCMNR.
    data lv_previous2 type FCMNR.
    if lv_month = 1.
    lv_previous1 = '12'.
    else.
    lv_previous1 - lv_month - 1.
    endif.
    if lv_previous1 = 1.
    lv_previous2 = '12'.
    else.
    lv_previous2 - lv_previous1 - 1.
    endif.
    Then do your lookup for the month name by reading the table returned from function module MONTH_NAMES_GET.

  • How to get an empty cell when SUM cells are empty?

    When doing a SUM, I want the result to be blank if there are no numbers yet. In Excel, if you have =SUM(A6:A30) with empty cells, the result is an empty cell.
    In Numbers, it's a zero.
    I know you can use =IF(SUM(A6:A30)>0,SUM(A6:A30),"") to put an empty string in the cell if there's nothing to add, but this doesn't work for negative numbers.
    I tried =SUMIF(A6:A30,"count(A6:A30)>0") and it puts a zero there even if all the cells are blank, and I don't think it's correct anyway.
    =IF(SUM(A6:A30)>0,SUM(A6:A30),(IF(SUM(A6:A30)<0,SUM(A6:A30),"")))
    works, but it seems rather cumbersome.
    Is there a better way?
    Ideas?

    Terrell Smith wrote:
    =IF(SUM(A6:A30)>0,SUM(A6:A30),(IF(SUM(A6:A30)<0,SUM(A6:A30),"")))
    works, but it seems rather cumbersome.
    </div>
    Hello
    The best way I found to solve your problem is:
    =IF(COUNT(A6:A30),SUM(A6:A30),"")
    Which reads:
    if at least one cell of the range (A6:A30) contains a numeric value returns SUM(A6:A30)
    else
    returns a blank cell.
    Of course, if the sum is nil the displayed [thanks you Barry ;-)] value will be a zero.
    Maybe it's what schubladenschrank was offering but I don't read Deutsch.
    Just for info, your formula may be shorten as:
    =IF(SUM(A6:A30)=0,"",SUM(A6:A30))
    Yvan KOENIG (from FRANCE samedi 2 février 2008 13:55:43)

  • Ios 5 Update New Features says that iCal now has a week view for iPhone but after updating last weekend, I don't see any week view--just List, Day and Month..How do I get the week view?

    ios 5 Update New Features says that calendar now has a week view but after updating my iPhone 4 last weekend, I don't see any week view for iCal--just List, Day and Month as in the past. Is the weekly view available for iCal and if so, how do I access it?

    Rotate your phone to landscape.

  • How to get days between two dates

    Hi ,
    How to get days between two dates.
    Regards,
    Ramesh.

    Hi Ramesh,
    REPORT ZDATEDIFF.
    DATA: EDAYS   LIKE VTBBEWE-ATAGE,
          EMONTHS LIKE VTBBEWE-ATAGE,
          EYEARS  LIKE VTBBEWE-ATAGE.
    PARAMETERS: FROMDATE LIKE VTBBEWE-DBERVON,
                TODATE   LIKE VTBBEWE-DBERBIS DEFAULT SY-DATUM.
    call function 'FIMA_DAYS_AND_MONTHS_AND_YEARS'
      exporting
        i_date_from          = FROMDATE
        i_date_to            = TODATE
      I_FLG_SEPARATE       = ' '
      IMPORTING
        E_DAYS               = EDAYS
        E_MONTHS             = EMONTHS
        E_YEARS              = EYEARS.
    WRITE:/ 'Difference in Days   ', EDAYS.
    WRITE:/ 'Difference in Months ', EMONTHS.
    WRITE:/ 'Difference in Years  ', EYEARS.
    INITIALIZATION.
    FROMDATE = SY-DATUM - 60.

  • How to get UTF-8 encoding when create XML using DBMS_XMLGEN and UTL_FILE ?

    How to get UTF-8 encoding when create XML using DBMS_XMLGEN and UTL_FILE ?
    Hi,
    I do generate XML-Files by using DBMS_XMLGEN with output by UTL_FILE
    but it seems, the xml-Datafile I get on end is not really UTF-8 encoding
    ( f.ex. cannot verifying it correct in xmlspy )
    my dbms is
    NLS_CHARACTERSET          = WE8MSWIN1252
    NLS_NCHAR_CHARACTERSET     = AL16UTF16
    NLS_RDBMS_VERSION     = 10.2.0.1.0
    I do generate it in this matter :
    declare
    xmldoc CLOB;
    ctx number ;
    utl_file.file_type;
    begin
    -- generate fom xml-view :
    ctx := DBMS_XMLGEN.newContext('select xml from xml_View');
    DBMS_XMLGEN.setRowSetTag(ctx, null);
    DBMS_XMLGEN.setRowTag(ctx, null );
    DBMS_XMLGEN.SETCONVERTSPECIALCHARS(ctx,TRUE);
    -- create xml-file:
    xmldoc := DBMS_XMLGEN.getXML(ctx);
    -- put data to host-file:
    vblob_len := DBMS_LOB.getlength(xmldoc);
    DBMS_LOB.READ (xmldoc, vblob_len, 1, vBuffer);
    bHandle := utl_file.fopen(vPATH,vFileName,'W',32767);
    UTL_FILE.put_line(bHandle, vbuffer, FALSE);
    UTL_FILE.fclose(bHandle);
    end ;
    maybe while work UTL_FILE there is a change the encoding ?
    How can this solved ?
    Thank you
    Norbert
    Edited by: astramare on Feb 11, 2009 12:39 PM with database charsets

    Marco,
    I tryed to work with dbms_xslprocessor.clob2file,
    that works good,
    but what is in this matter with encoding UTF-8 ?
    in my understandig, the xmltyp created should be UTF8 (16),
    but when open the xml-file in xmlSpy as UTF-8,
    it is not well ( german caracter like Ä, Ö .. ):
    my dbms is
    NLS_CHARACTERSET = WE8MSWIN1252
    NLS_NCHAR_CHARACTERSET = AL16UTF16
    NLS_RDBMS_VERSION = 10.2.0.1.0
    -- test:
    create table nh_test ( s0 number, s1 varchar2(20) ) ;
    insert into nh_test (select 1,'hallo' from dual );
    insert into nh_test (select 2,'straße' from dual );
    insert into nh_test (select 3,'mäckie' from dual );
    insert into nh_test (select 4,'euro_€' from dual );
    commit;
    select * from nh_test ;
    S0     S1
    1     hallo
    1     hallo
    2     straße
    3     mäckie
    4     euro_€
    declare
    rc sys_refcursor;
    begin
    open rc FOR SELECT * FROM ( SELECT s0,s1 from nh_test );
    dbms_xslprocessor.clob2file( xmltype( rc ).getclobval( ) , 'XML_EXPORT_DIR','my_xml_file.xml');
    end;
    ( its the same when using output with DBMS_XMLDOM.WRITETOFILE )
    open in xmlSpy is:
    <?xml version="1.0"?>
    <ROWSET>
    <ROW>
    <S0>1</S0>
    <S1>hallo</S1>
    </ROW>
    <ROW>
    <S0>2</S0>
    <S1>straޥ</S1>
    </ROW>
    <ROW>
    <S0>3</S0>
    <S1>m㢫ie</S1>
    </ROW>
    <ROW>
    <S0>4</S0>
    <S1>euro_€</S1>
    </ROW>
    </ROWSET>
    regards
    Norbert

  • Today my money is deducted Rs.60 when I try to download paid applications of any amount and I am getting message transaction declined, so why my money is deducted. I lost almost Rs 480 rupees . So how to get refund and how to make card working?

    Today my money is deducted Rs.60 when I try to download paid applications of any amount and I am getting message transaction declined, so why my money is deducted. I lost almost Rs 480 rupees . So how to get refund and how to make card working?

    Today my money is deducted Rs.60 when I try to download paid applications of any amount and I am getting message transaction declined, so why my money is deducted. I lost almost Rs 480 rupees . So how to get refund and how to make card working?

  • Date Formatting - Day and Month Switching Places

    I am starting to get really frustrated with this problem; at first it was just a nuisance, but now when I actually want and need to do something important with Numbers it has become a major headache.
    When I first select a formatting and enter a date it works fine. I enter, e.g., "1 Aug 2009" and Numbers formats it "1 August, 2009" as per my formatting selection. However, when I go to change the formatting to, e.g., "day of week, day month, year" my "1 August 2009" suddenly becomes "Thursday, 8 January, 2009" - it switches the day and month values around! This happens no matter which format I choose, and no matter what I do - whether I enter the day first or month first, American or European - it always switches them around when I go to change the format. It's infuriating!
    Does anyone have any suggestions? What am I to do?

    Welcome to Apple Discussions
    I believe the problem is that you have US formats for dates. Select the cells/columns that you want your date format to apply to then click the cell format inspector (the 42 in a box icon) & choose Custom… from the cell format drop-down. You will be presented with a box that allows you to make your own format. Click & hold on any of the little "lozenges" in the input bar & move them around. You may need to add a space to get the proper result.

  • I updated my Itunes the other day and now, when clicking on the itunes icon, the program does not open?? I have tried uninstalling and reinstalling, resetting the computer, checking permissions, running as adminstrator.. nothing is working?? Help!!

    I updated my Itunes the other day and now, when clicking on the itunes icon, the program does not open?? I have tried uninstalling and reinstalling, resetting the computer, checking permissions, running as adminstrator.. nothing is working?? Help!!

    Amazing steps you've done so far! The great news is this is very unlikely an issue with your iPhone.
    I've run into a similar issue lately as well. I narrowed it down to one song that was causing 30 songs not to sync. I removed the song from the sync list (unchecked it) and all 29 songs were able to sync.
    You may be running into a similar issue. This may be a problem with this version of iTunes, an issue with one song or a group of songs; hard to know for sure. It's important to narrow down and isolate the cause. Most imporantly get that music back on there!
    The way to narrow down the casue add just a few songs at a time (even 1, just to get that first sync finished). Manually syncing is what you'll need here.
    Plug in your iPhone, on the Summary screen (shows a picture of your iPhone, the iOS version, Restore iPhone....; etc). Under the Options area at the bottom choose to Manually Manage Videos and Music then choose Apply in the lower right. The music that's on your iPhone now should be removed from your iPhone now. You're now able to sync music manually.
    The link below explains how to drag the songs from the iTunes library on the computer on to your iPhone which will start the sync. Add just one song just to see if you can get 1 of those hundreds of songs on there. If you can, awesome! Keep adding until you find the song or group of songs that are causing this issue.
    http://support.apple.com/kb/HT1535
    Please let me know how things are going.
    Cheers!

  • How to get iMessage to work when all it says is waiting for activation

    How to get iMessage to work when all it says is waiting for activation

    Hi Howell,
    Welcome to Apple Support Communities.
    This article on troubleshooting FaceTime activation has some steps you can try:
    iOS: Troubleshooting FaceTime and iMessage activation
    http://support.apple.com/kb/ts4268
    Have a great day,
    Jeremy

Maybe you are looking for