To find months and days between 2 dates

Hi,
I want to find the months and days between 2 dates.
For Eg.
Date-1 : 25-Aug-2013
Date-2 : 23-Oct-2013
If we consider every month as 30 days it should give
25-Aug-2013 to 30-Aug-2013 = 6 days
01-Sep-2013 to 30-Sep-2013 = 1 Month
23-Oct-2013 to 30-Oct-2013 =   8 days
Total = 1 month and 14 days.
Kindly help at the earliest.
Thanks & Regards
Suresh

SureshM wrote:
Hi,
I want to find the months and days between 2 dates.
For Eg.
Date-1 : 25-Aug-2013
Date-2 : 23-Oct-2013
If we consider every month as 30 days it should give
25-Aug-2013 to 30-Aug-2013 = 6 days
01-Sep-2013 to 30-Sep-2013 = 1 Month
23-Oct-2013 to 30-Oct-2013 =   8 days
Total = 1 month and 14 days.
Kindly help at the earliest.
Thanks & Regards
Suresh
That's not a good idea though.  Be considering every month as 30 days, then comparisons over larger date ranges (years) will be out by more and more days the larger the difference gets.
Your example is also wrong.
For Eg.
Date-1 : 25-Aug-2013
Date-2 : 23-Oct-2013
If we consider every month as 30 days it should give
25-Aug-2013 to 30-Aug-2013 = 6 days
01-Sep-2013 to 30-Sep-2013 = 1 Month
23-Oct-2013 to 30-Oct-2013 =   8 days
The last one should be:
01-Oct-2013 to 23-Oct-2013 = 23 days
giving a result of 1 month and 29 days.
Oracle provides a months_between function to do the calculation.
SQL> select months_between(date '2013-10-23', date '2013-08-25') from dual;
MONTHS_BETWEEN(DATE'2013-10-23',DATE'2013-08-25')
                                       1.93548387
But of course, because the number of days in a month varies, it's not exacly known what the decimal part of the number represents.
However, if you combine methods, using months_between to get the months, and then assume 30 days for a month to get the days part from the remainder, it's more consistent over longer periods...
SQL> ed
Wrote file afiedt.buf
  1  with dates as (select date '2013-08-25' as date_from, date '2013-10-23' as date_to from dual)
  2  --
  3  select months_between(date_to, date_from)
  4        ,trunc(months_between(date_to, date_from)) as months
  5        ,round(mod(months_between(date_to, date_from),1)*30) as days
  6* from dates
SQL> /
MONTHS_BETWEEN(DATE_TO,DATE_FROM)     MONTHS       DAYS
                       1.93548387          1         28

Similar Messages

  • Months and days between dates

    What is the formula to find the months and days between dates

    Tricky... The first problem is the intended result. Months have a varying number of days in them, days and weeks have set values. For example the difference between 1st July and 1st September is 2 months but this does not give an accurate count of the number of days (61).
    It would be better to calculate the number of days difference and forget the months.
    You would need a lookup table showing a numeric value for each date that would show each date with a day value from a starting point. If your earliest date is 01/01/2000 then that would be day zero. Then using the lookup table calculate the day value for your beginning and end dates. Subtract one from the other to get the number of days.
    If all your dates are from this year:
    You can create your own Cell Format (call it day of the year) Select the Type: Date & Time
    drag the icon for Day of Year into the box and delete the others.
    Convert your dates to this new Format, subtract one value from the other to get the number of days difference.

  • Find No Of Days Between Two Dates

    hello and hi
    me have a data base given below
    me want to find no of days between '16-oct-2008' and '02-NOV-2008'
    Emp Start_Date End_Date
         25551          10/16/2008     10/30/2008
         25551          10/31/2008     11/30/2008
    any body help me pls
    thanks

    Ok, 2 points:-
    1. Simply subtract the two dates and use ROUND
    2. This is an Oracle Forms forum, post query related doubts on SQL/PLSQL forum

  • Function module to find no of days between two dates

    hi everybody i want a function module to find no of days between two dates

    Function module              /SDF/CMO_DATETIME_DIFFERENCE
    Uppercase/Lowercase
    Runtime:        59,629 Microseconds
      Import parameters               Value
      DATE1                           01.01.2007
      TIME1                           00:00:00
      DATE2                           31.12.2007
      TIME2                           00:00:00
      Export parameters               Value
      DATEDIFF                                                    364  TIMEDIFF                                                      0
      EARLIEST                        1

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

  • Find no. of days between dates

    Hi guys,
    I have 5 dates with me, 2 of which are Key Figures and 3 are of Char. date type. Now, I have to find no. of days between these dates using various permutation and combination i.e. it can be between 2 KF's or 2 Char. types or 1 KF and 1 Char. type as well.
    1) I think finding no. of days between 2 KFs can be done using Cumulative KF.
    2) I tried to find no. of days between 2 Charac. by creating a Formula (2 variables with Replacement Path) and then finding the difference. But the output seems to be wrong.
    eg. 27.02.2009     -    19.01.2009  = 108 days, which is wrong!
         (Posting date)      (clearing date)
    3) I also have to do it between 1 KF and 1 Char. date type, tried creating 1 variable for Char. and then subtracting with KF, but Report shows 'X' in the output!
    Any suggestions?
    Thanks.

    Hi,
    You can do it by using Customer Exits and Replacement path Variables..
    see teh floowing thread.
    Difference in days
    Thanks
    Reddy

  • Get Months and Days -- Problem with months_between

    Hi,
    For a report, I need to convert days as months and days for eg 370 days as 12 months 5 days.
    I tried below query
    with t as (
    select
    maturity_date - value_date tenor
    from account_master)
    select
    trunc(mod(months_between(trunc(sysdate,'YYYY')+ tenor,trunc(sysdate,'YYYY')),30)) month,
    (trunc(sysdate,'YYYY')+tenor)-add_months(trunc(sysdate,'YYYY'),trunc(months_between(trunc(sysdate,'YYYY')+ tenor,trunc(sysdate,'YYYY')))) "day"
    from t
    And i am getting output as
    MONTH day
    11 30
    23 30
    11 30
    1 5
    11 30
    11 30
    11 30
    0 6
    11 30
    for Number of days
    TENOR
    365
    730
    365
    36
    365
    365
    365
    6
    365
    As you can see for 365 days i am getting Months as 11 and days as 30
    and for 730 days i am getting months as 23 and days as 30.
    I want 365 days as 12 months and 0 days.
    I think it is months_between function that is creating this problem.
    Can anyone suggest another way of accomplishing this?
    Thanks and Regards
    Amit Trivedi

    2008 is a leap year! so it's 366 days long. therefore, 365 days is really only 11 months and 30 days (if you start counting from Jan 01, which is what you are doing).
    so the number of months and days between is dependent on the starting date (consider a range of 30 days starting on Jan 01, Feb 01 (leap year), Feb 01 (non-leap year) and Apr 01).
    so:
    with t as (
    select maturity_date - value_date tenor, value_date d1 from account_master
    select
    trunc(months_between(d1+ tenor,d1)) months,
    d1+tenor - add_months(d1,trunc(months_between(d1+ tenor,d1),30)) days
    from t
    or better yet:
    select
    trunc(months_between(maturity_date,value_date)) months,
    maturity_date - add_months(value_date,trunc(months_between(maturity_date,value_Date))) days
    from account_master
    /

  • Difference between 2 dates in form of years,months and days.

    Hi friends,
      i need one function module for finding difference between 2 dates and the output is
    no. of years
    no.of months
    no. of days.
    it means the input is begin date and end date
    output is no.of years,no.of months and no.of days.
    for example begin date is today i.e., 08/02/2008 (dd/mm/yyyy) and end date is 07/03/2008 then the output is
    no.of years -
      0,
    no.of months----
      1,
    no.of days----
      0.
    and one more example if begin date 08/02/2008
    (dd/mm/yyyy) and end date is 01/02/2008 then the output is
    no.of years -
    0,
    no.of months----
      0,
    no.of days----
    -7..
    Please help me it's very urgent

    Hi,
    Use FM HR_AUPBS_MONTH_DAY.
    It Calculate the years, months, days & cal days between 2 dates.
    Hi,
    The FM is 'FIMA_DAYS_AND_MONTHS_AND_YEARS'
    Check the following example:
    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.
    Also You can write your own function module for this..
    just extract day and month and year from the two dates and then get the difference.
    suppose date 1 - y1m1d1
    date 2 = y2m2d2
    data : y1(2) type n,
    m1(2) type n,
    d1(2) type n,
    y2(2) type n,
    m2(2) type n,
    d2(2) type n,
    y1 = date1(4).
    m1 = date1+4(2).
    d1 = date1+6(2).
    y2 = date2(4).
    m2 = date2+4(2).
    d2 = date2+6(2).
    then get the differnce between years and days and months and store them in ur variables
    Reward Points if found helpfull..
    Cheers,
    Chandra Sekhar.

  • Date separate year, month and day

    Hello everyone and thanks in advance, I'm new to this and the truth is not doing this.
    Well, I have a PDF with several pages which I designed and has been asking me in a complete date in the format dd / mm / yy and subsequent pages he asks me the same date of birth but in 3 separate fields, day , month and year. I want you when you enter the date the first copy and separate day month and year in others. I tried this but I get
    var array_datesol = datesol.split("/")
    var year = parseInt(array_datesol[2]);
    var month = parseInt(array_datesoll[1]);
    var day = parseInt(array_datesol[0]);
    this.getField('yearsol').value = year;
    this.getField('monthsol').value = month;
    this.getField('daysol').value = day;
    where is the initial field datesol date and year, month and day where they have to be separately
    thanks in advance

    Are you getting any errors in the JavaScript debugging console?
    You are using the syntax for the 'Custom JavaScript calculation' and this syntax can not be used in the 'simplified field notation. Also you can not use any JavaScript properties, objects, functions, control statments.
    When run in the console, I find you have a misspelling of the variable name 'datesol'. I also do not see where you are initializing the value for 'datesol'.
    var datesol = event.valueAsString;  // get value of this field
    var array_datesol = datesol.split("/") ; // make into an array
    this.getField('yearsol').value =array_datesol[2];  // get element year
    this.getField('monthsol').value = array_datesol[1];  // get month element - fixed variable name
    this.getField('daysol').value = array_datesol[0]; // get date element
    I would use one of the following so the other fields are only updated when a date has been entered and the leading zeros are displayed:
    this.getField('yearsol').value = '';
    this.getField('monthsol').value = '';
    this.getField('daysol').value = '';
    if(event.value != '') {
    // get parts of date and print with leading zeros
    var datesol = event.value;  // get value of this field
    var array_datesol = datesol.split('/') ; // make into an array
    this.getField('yearsol').value = util.printf('%,304.0f', array_datesol[2]);  // get element year
    this.getField('monthsol').value = util.printf('%,302.0f', array_datesol[1]);  // get month element - fixed variable name
    this.getField('daysol').value = util.printf('%,302.0f', array_datesol[0]); // get date element
    // or
    this.getField('yearsol').value = '';
    this.getField('monthsol').value = '';
    this.getField('daysol').value = '';
    if (event.value != '') {
    // get date parts and print with leading zeros
    var oDatesol = util.scand('dd/mm/yyyy', event.value); // get date object
    this.getField('yearsol').value = util.printf('%,302.0f',oDatesol.getFullYear());  // get element year
    this.getField('monthsol').value = util.printf('%,302.0f', oDatesol.getMonth() + 1);  // get month element - fixed variable name
    this.getField('daysol').value = util.printf('%,302.0f', oDatesol.getDate()); // get date element
    // or
    this.getField('yearsol').value = '';
    this.getField('monthsol').value = '';
    this.getField('daysol').value = '';
    if(event.vaue != '') {
    // get parts of date and format
    var oDatesol = util.scand('dd/mm/yyyy', event.value); // get date object
    this.getField('yearsol').value = util.printd('yyyy', oDatesol); // get element year
    this.getField('monthsol').value = util.printd('mm', oDatesol); // get month element - fixed variable name
    this.getField('daysol').value = util.printd('dd', oDatesol); // get date element
    If you are going to fill other field, you will need to use the '.valueAsStriing' property or '.toString()'  method to retain the leading zeros.

  • How do you find the difference in no. of days between 2 dates?

    How do you find the difference in no. of days between 2 dates ?

    There are 2 way to solve this: using java.util.GregorianCalendar or java.util.Date (like jesper1 suggested), depending what kind of solution You need:
            GregorianCalendar gc1 = new GregorianCalendar(2001, 01, 01, 23, 00, 00);
            GregorianCalendar gc2 = new GregorianCalendar(2001, 01, 03, 10, 00, 00);
            // 1st way using GregorianCalendar
            int diff1 = gc1.get(GregorianCalendar.DATE) - gc2.get(GregorianCalendar.DATE);
            System.out.println("Differnce: " + diff1);
            // 2nd way using Date
            int diff2 = (int)(gc1.getTime().getTime() - gc2.getTime().getTime()) / (24 * 60 * 60 * 1000);
            System.out.println("Differnce: " + diff2);Note: There are 2 days between the given dates, but exactly 1 day and 11 hours.
    The first solution returns "-2", the second returns "-1".
    (... and a 4th posting also won't help ...)

  • Subtract   two dates to get   months and days

    I havew to subtract two dates and get the differnce ,
              Date issuedDate= myobj.getIssueDate();
              Date expirationDate=DateUtils.addMonths(issuedDate, 6);
              long timeDiff=expirationDate.getTime()-new Date().getTime();
              long daysRemaning=timeDiff/86400000;this is code I get the number of days between the issue date and todays date.now my client wants not just days but months and days , i need suggestions on how to get days and months between any two given dates

    I have read that it is best to use java.util.Calendar for almost any time related issue.
    With some switch statements and a for loop, I think the Calendar class could solve the problem.

  • Working days between two date fields and Changing Factory Calendar

    Hi,
    I have to calculate working days between two date fields excluding the weekends and public holidays for Switzerland.
    I have written the routine using factory calender and its working fine except for two problems now:
    1. If any one of the date field is empty then teh rsult should be zero.
    2. And the below code is working from 1996 but my cleints wants it to work for years before 1996 as well.
    I also tried to change the Start date in SCAL for factory calendar but it says enter values between 1995 to 2020.
    I am new to ABAP. Please help me how i can achieve these for below code.
    DATA: IT_HOLIDAYS type TABLE OF ISCAL_DAY,
          IS_HOLIDAYS TYPE ISCAL_DAY.
    DATA: T_DATE TYPE SY-DATUM,
          P_DATE TYPE SY-DATUM.
    DATA : X_DATE(4) TYPE C.
    DATA: CNT TYPE I.
    REFRESH : IT_HOLIDAYS.
    CLEAR : IT_HOLIDAYS.
    T_DATE = SOURCE_FIELDS-/BIC/ZCCCHP812.
    P_DATE = SOURCE_FIELDS-/BIC/ZCCCHP810.
    CALL FUNCTION 'HOLIDAY_GET'
    EXPORTING
    HOLIDAY_CALENDAR = 'CH'
    FACTORY_CALENDAR = 'CH'
    DATE_FROM = P_DATE
    DATE_TO   = T_DATE
    TABLES
    HOLIDAYS = IT_HOLIDAYS
    EXCEPTIONS
    FACTORY_CALENDAR_NOT_FOUND = 1
    HOLIDAY_CALENDAR_NOT_FOUND = 2
    DATE_HAS_INVALID_FORMAT = 3
    DATE_INCONSISTENCY = 4
    OTHERS = 5.
    DESCRIBE TABLE IT_HOLIDAYS LINES CNT.
    X_DATE = T_DATE - P_DATE - CNT.
    RESULT = X_DATE.
    Please help
    Regards
    Zabina
    Edited by: Syed786 on Nov 2, 2011 9:15 AM

    Hi Zabina,
    Try this function module  'DURATION_DETERMINE'.
    Give the factory calendar and unit as DAY
    With regards,
    Rajesh

  • Query on fetching the no.of days between Invoice date and due date in rtf template embedded BI Publisher Report

    Hi Experts,
    We have a requirement to fetch the value of 'No of days' between Invoice date and due date (Two variable date fields on the template) in an Analysis.
    Please let me know the procedure of how to achieve the same.
    Regards,
    Rev

    it's good for ideas but implementation a bit different
    Oracle Business Intelligence Publisher Report Designer's Guide
    This function provides a 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 the Gregorian calendar. The syntax is as follows:
    <?xdoxslt:date_diff(‘format’, ‘YYYY-MM-DD’, ‘YYYY-MM-DD’, $_XDOLOCALE, $_XDOTIMEZONE)?>
    where
    format is the time value for which the difference is to be calculated
    Example:
    <?xdoxslt:date_diff(‘d’, ‘2006-04-08’, ‘2006-04-01’, $_XDOLOCALE, ‘America/Los_Angeles’)?>
    returns
    -7

  • Acrobat Pro XI transposes numbers for month and day in dates when saving optimized pdf to Excel spreadsheet.

    Using Adobe Acrobat Pro XI and Excel 14.3.8 on a mac. 
    Saved PDF as "optimized PDF" then "save as other" > spreadsheet > Microsoft Excel Workbook.
    Problem: numbers in some random dates are  transposed so that month and day are reversed.  No particular pattern to these errors.  Only fix we've found is to go through and manually check and correct the date errors - there are hundreds of these errors in the document so this is not a good solution.
    (Note: Excel columns with dates are specified as "date" fields. All dates are formatted as m/d/yy)
    Any ideas what's causing this problem problem and how to fix it? 
    Thanks in advance!

    [discussion moved to Creating, Editing & Exporting PDFs forum]

  • How to get the difference of two dates in years,months and days

    Hi friends,
    how to get the difference of two dates in years,months and days
    for ex 2 years 3 months 13 days
    select (sysdate-date_Start) from per_periods_of_service
    thanks

    Something like this...
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select to_date('17-nov-2006','dd-mon-yyyy') as c_start_date, to_date('21-jan-2008','dd-mon-yyyy') as c_end_date from dual union all
      2             select to_date('21-nov-2006','dd-mon-yyyy'), to_date('17-feb-2008','dd-mon-yyyy') from dual union all
      3             select to_date('21-jun-2006','dd-mon-yyyy'), to_date('17-jul-2008','dd-mon-yyyy') from dual
      4             )
      5  -- end of test data
      6  select c_start_date, c_end_date
      7        ,trunc(months_between(c_end_date, c_start_date) / 12) as yrs
      8        ,trunc(mod(months_between(c_end_date, c_start_date), 12)) as mnths
      9        ,trunc(c_end_date - add_months(c_start_date, trunc(months_between(c_end_date, c_start_date)))) as dys
    10* from t
    SQL> /
    C_START_D C_END_DAT        YRS      MNTHS        DYS
    17-NOV-06 21-JAN-08          1          2          4
    21-NOV-06 17-FEB-08          1          2         27
    21-JUN-06 17-JUL-08          2          0         26
    SQL>But, don't forget that different months have different numbers of days, and leap years can effect it too.

Maybe you are looking for

  • Error while deploying the demo

    hi all, this is my FP log file,i got this sql exceptions: ORA-01920: user name 'JMSUSER' conflicts with another user or role name ORA-00955: name is already used by an existing object then atlast the log file shows getESBMetadata: BUILD SUCCESSFUL To

  • How to send bulk email to contacts stored in SharePoint 2010 lists

    How do I send a group email to contacts stored in SP2010 List? I have a very large Customer List with various categories(supervisors, employees..etc). I would like to filter the list(say all supervisors) and send them an email directly from sharepoin

  • MacBookPro 10.7.5 shuts itself down and restarts after around 5 minutes of non use.

    This started after my last security update last week. Is there a setting I need to change? or is this a quirk? It's infuriating.

  • Dual monitor freeze on sleep

    Mac OS X 10.9.5.  Current model iMac:  3.5GHh i7.  32GB main mem.  NVDIA GeForce GTX 780M 4096MB. Runs fine without a second monitor.  Sleep, both manual and timeout, works fine.  Press any key awakes. Plug in a second monitor (2 month old 27" Thunde

  • Extracting data from multiple tables, avoiding duplicates.

    Hi I currently have two tables called Book and JournalPaper, both of which have a column called Publisher. Currently the data in the Publisher column is the Publisher name that is entered straight into either table and has been duplicated in many cas