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.

Similar Messages

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

  • Convert two dates difference to number of years, months and days

    Post Author: gigimonu
    CA Forum: Formula
    I wanted to write a formula (if there is a function I can use) that can convert a date difference to total number of years, months and days example
    adate = 10/22/2006
    ?xdate = current date - adate (answer should be 1 years, 0 months and 0 days)
    Please help
    Thanks

    Post Author: V361
    CA Forum: Formula
    [Years, Months, Days]
    DATEVAR FROMDATE := DATE(2000,01,01); // FROM DATE
    DATEVAR TODATE := CURRENTDATE; // TO DATE
    NUMBERVAR YEARS;
    NUMBERVAR MONTHS;
    NUMBERVAR DAYS;
    STRINGVAR DIFF;
    DATEVAR TEMP;
    IF TODATE < FROMDATE THEN
    (TEMP := TODATE;
    TODATE := FROMDATE;
    FROMDATE := TEMP);
    YEARS := DATEDIFF('YYYY',FROMDATE,TODATE);
    IF YEARS > 2 THEN
    (YEARS := YEARS - 2;
    TEMP := DATE(DATEADD("M",YEARS * 12,FROMDATE));)
    ELSE
    (YEARS := 0;
    TEMP := FROMDATE);
    WHILE TRUE DO
    (TEMP := DATE(DATEADD('M',1,TEMP));
    IF TEMP > TODATE THEN
    EXIT WHILE;
    MONTHS := MONTHS + 1);
    DAYS := DATEDIFF('D',DATE(DATEADD('M',-1,TEMP)),TODATE);
    IF MONTHS > 12 THEN
    (YEARS := YEARS + INT(MONTHS/12);
    MONTHS := MONTHS MOD 12);
    DIFF := IIF(YEARS>0 ,TRIM(TOTEXT(YEARS,0)) & " YEARS " ,"0 YEARS ") &
    IIF(MONTHS>0,TRIM(TOTEXT(MONTHS,0))& " MONTHS ","0 MONTHS ")&
    IIF(DAYS>0 ,TRIM(TOTEXT(DAYS,0)) & " DAYS" ,"0 DAYS");

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

  • FM to get the number of days in Year,month and days by giving number of day

    Hi ALL,
    This is quit differnt.
    I need to give input the 'start date' and the 'number of days' and get the total days from the start date in year,month and day format.
    for example.
    start date :01.01.2009
    number of days as 32
    then i should get
    years:0
    months :1
    days :1
    Pleas help me out.

    hi Anusha,
    first u pass the date and the days to the following fm you will get the result date....
    data:date type sy-datum,
          r_date(10) type c.
    date = sy-datum.
    CALL FUNCTION 'CALCULATE_DATE'
    EXPORTING
       DAYS              = '32'
       MONTHS            = '0'
       START_DATE        = date
    IMPORTING
       RESULT_DATE       = r_date
    write:/ r_date.
    then you need to pass the result date and the date to the following fm to get the required output...
    CALL FUNCTION 'HR_HK_DIFF_BT_2_DATES'
        EXPORTING
          date1                   = r_date
          date2                   = date
        IMPORTING
          years                   = v_years
         months                 = v_months
        days                     = v_days
        EXCEPTIONS
          invalid_dates_specified = 1
          OTHERS                  = 2.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
    here u will get the difference in days,  months and year...
    i hope u wil get help from this...
    regards
    Ashu  Singh

  • I need the age to show in Years Months and Days

    Post Author: LOgle0917
    CA Forum: Formula
    NumberVar DoBVar := IIF((100 * MONTH({CHARTING.CHARTINGDATE}) + DAY({CHARTING.CHARTINGDATE})<(100 * MONTH({DEMOGRAPHICS.BIRTHDATE})+ DAY({DEMOGRAPHICS.BIRTHDATE}))),1, 0);NumberVar MthVar := (DATEDIFF("m",{DEMOGRAPHICS.BIRTHDATE},{CHARTING.CHARTINGDATE}) - DobVar) MOD 12;NumberVar YrsVar := DATEDIFF("yyyy",{DEMOGRAPHICS.BIRTHDATE},{CHARTING.CHARTINGDATE}) - DobVar;StringVar MthYrs := TOTEXT(YrsVar,0) + " years " + TOTEXT(MthVar,0) + " months";
    This returns Years and Months what do I need to add to it to return days?
    Thanks!

    Post Author: SKodidine
    CA Forum: Formula
    Here is a formula that I modified for CR from a Visual FoxPro function by Ramani Subramanian G.
    Create a separate formula to replace your calculations for datediff and paste this replacing the values of fromdate and todate with {DEMOGRAPHICS.BIRTHDATE} and{CHARTING.CHARTINGDATE} respectively.
    DATEVAR FROMDATE := DATE(2000,01,01);   // FROM DATE
    DATEVAR TODATE   := CURRENTDATE;        // TO DATE
    NUMBERVAR YEARS;
    NUMBERVAR MONTHS;
    NUMBERVAR DAYS;
    STRINGVAR DIFF;
    DATEVAR   TEMP;
    IF TODATE < FROMDATE THEN
    (TEMP     := TODATE;
    TODATE   := FROMDATE;
    FROMDATE := TEMP);
    YEARS := DATEDIFF('YYYY',FROMDATE,TODATE);
    IF YEARS > 2 THEN
    (YEARS := YEARS - 2;
    TEMP  := DATE(DATEADD("M",YEARS * 12,FROMDATE));)
    ELSE
    (YEARS := 0;
    TEMP  := FROMDATE);
    WHILE TRUE DO
    (TEMP := DATE(DATEADD('M',1,TEMP));
    IF TEMP > TODATE THEN
        EXIT WHILE;
    MONTHS := MONTHS + 1);
    DAYS := DATEDIFF('D',DATE(DATEADD('M',-1,TEMP)),TODATE);
    IF MONTHS > 12 THEN
    (YEARS  := YEARS + INT(MONTHS/12);
    MONTHS := MONTHS MOD 12);
    DIFF := IIF(YEARS>0 ,TRIM(TOTEXT(YEARS,0)) & " YEARS " ,"0 YEARS ") &
            IIF(MONTHS>0,TRIM(TOTEXT(MONTHS,0))& " MONTHS ","0 MONTHS ")&
            IIF(DAYS>0  ,TRIM(TOTEXT(DAYS,0))  & " DAYS"   ,"0 DAYS");

  • Converting a number into years, months and days...

    Hi everyone,
    I have a number say 399.
    I need to know how many years and months constitute that number.
    For eg 399 would be 1yr, 1 month and 4 days.
    So I need the answer as 1 yr and 1 month.
    Is there any inbuilt funtion to say this?
    Thanks
    Kishore

    following a quick (and dirty) solution.
    What about the leap years?
    define v_startdate='01-01-2003'
    define v_juliandays=399
    SELECT
    TRUNC (         MONTHS_BETWEEN ( TO_DATE('&&v_startdate','MM-DD-YYYY') + &&v_juliandays,
                                     TO_DATE('&&v_startdate','MM-DD-YYYY')
                                   )/12) "Years",
    TRUNC ( MOD (   MONTHS_BETWEEN ( TO_DATE('&&v_startdate','MM-DD-YYYY') + &&v_juliandays,
                                     TO_DATE('&&v_startdate','MM-DD-YYYY')
                                   ) ,12)) "Months"
    FROM DUAL;

  • Mailed iCal attachment shows right date but clicking will put appointment on wrong year, month and day. Even names involved are wrong!

    Running Mountain Lion on MacBook Air and MacBook Pro. Suddenly a mailed iCal attachment showing the right date, time and attendees ends up years and months off on iCal with totally wrong attendiees, when clicked in Mail. iCal synced to iCloud. This may be very trivial for some of you but I need help, please.
    Thank you.

    I ran into this exact issue after migrating a time machine backup from an older macbook air to a new macbook pro.
    The following steps solved my issue:
    1) Backup your current mac
    2) Create a new user account on your mac, and login to that account.
    3) While logged into the new user account, right click the time machine drive and select "get info" > Click the lock icon at the lower right corner so that you can make permission changes. Then Click on the "+" sign and add your new user account to the "Sharing & Permissions" window. Be sure to grant your new user "Read & Write" privileges and when you have done so, click on the down arrow and select "apply to enclosed items" This step will allow you to copy the library folder from your old user account to the new account without hitting any permission issues.
    4) Download "TinkerTool" (An application that allows you to enable the viewing of any and all hidden files and folders on your local or mounted hard drives) and check the box that reads "Show Hidden and System Files" and then click "Relaunch Finder.
    5) Lastly copy the Library folder from the older user account on the time machine backup drive to the new user's library folder. Also be sure to copy your Desktop, Documents, Pictures, and Music folders to the new account as well. Open Mac mail and follow the instructions to import the previous accounts mail messages. Once you receive future ics attachments or calendar invites you should be able to click on them and load the proper date and time within your iCal application.
    This worked for me and I hope it works for you.
    Thanks,
    Chris Sampson

  • Why can't i get the correct DAY_OF_WEEK given year, month and day

    public String getPayrollRange(String whichhalf) throws SQLException{
    int month_today = today.get(Calendar.MONTH) + 1;
    int year_today = today.get(Calendar.YEAR);
    int day_today = today.get(Calendar.DAY_OF_MONTH);
    int end_day = 0;
    int dayofweek = 0;
    try{ connect();
    str = "SELECT value FROM DEFAULTS WHERE variable LIKE '"+whichhalf+"%cutoff'";
    rs = execSQL(str);
    if(rs!=null)
    { if(rs.next())
    end_day = rs.getInt("value");
    rs.close();
    dbCon.close();
    //--------------- THIS IS THE MOST IMPT PART -----------------------
    // i need to be able to set a Calendar object based on the integer variables
    // my problem is when i retrieve the DAY_OF_WEEK for the given_date variable
    Calendar given_date = new GregorianCalendar(year_today, month_today, 28);
    str = given_date.toString();
    }catch(Exception e) {
    e.printStackTrace();
    return str;
    }

    http://developer.java.sun.com/developer/qow/archive/152
    index.jsphi! the link was a great help but 'now' refers to the current date.
    my problem really is when a user specifies a given date and i'd like to get its DAY_OF_WEEK. i don't wanna use sql to get the DAYNAME.
    pls help!

  • Difference between Data Grid and Data Forms

    Hi all,
    What is the difference between data grid and data forms.

    Data entry forms are pre defined and are generally used to manually input data into reporting (financial statement) schedules.
    They can also be used for reviewing purposes and it gives users a presentable / and consistent format to view data in Hyperion.
    Data grids are the equivalent of pivot tables in excel. It should be used for ad hoc purposes to view / analyse data in whatever form you choose. The user has the flexibility to choose what they see in the rows, columns and page dimensions.
    One of the main differences between data entry forms and data grids is that you can’t export data grids to excel whereas you can with data entry forms. Other differences are:
    1. Run consolidation, translation, promotion from data grids but not in data entry forms.
    2. You can link other data entry forms to a data entry form
    3. Data entry forms offer greater formatting options than in data grids i.e. colours, fonts, bold, italics.
    At the end of the day, they are similar and there is no reason why you can’t have (use) both. It all depends on your local needs on how best you use both.
    I hope above information helps.

  • 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 date difference in terms of years,months and also days

    Tool : Eclipse
    Framework : JSF & Springs
    JRE : jdk1.5.0_06
    Iam using oracle 10G DB as back end.I have two date fields in a table.
    1)premium_paying_start_date
    2)premium_paying_end_date
    Iam getting these two dates from the database and storing these values within a entity.Now in the delegate layer,
    i have to get the premium_term i.e, the difference between the two dates(premium_paying_end_date-premium_paying_start_date).
    The difference should show the year,month and no of days difference.
    For example :
    premium_paying_start_date : 14-10-1984
    premium_paying_end_date : 01-03-2008
    Difference should be : 23 Y : 4 M : 15 D (Y = years, M = months , D= days)
    So please give me the solution for this.

    Difference should be : 23 Y : 4 M : 15 D (Y = years, M = months , D= days)
    So please give me the solution for this.How did you determine what the difference should be?
    ~

  • Difference between data form and data grids

    Can anybody tell me what is the difference between data form and data grid.
    Regards

    data forms have restricted access. user can not access all the dimension and members, based on his role and authentication can access the form.
    data grid r used for calculation, currency translation and coslidation and it consists of menu of options for diffrent consolidation based on cell status.
    data grid can have line item information, description and cell status information.

  • Find difference between date

    I need to know how i can find difference between date
    like Joining date: 01-jan-2009 Today 10-jan-2010 result will be "1 year 10 days"
    I need it in Oracle forms 6i. plz help me...

    Hi,
    In oracle forms you can use
    RESULT :=
    TRUNC ((:date2 - :date1 + 1) / 365)
    || ' year and '
    || MOD (:date2 - :date1 + 1, 365)
    || ' days';
    in sql you can use
    SELECT TRUNC ((:date2 - :date1 + 1) / 365)
    || ' year and '
    || MOD (:date2 - :date1 + 1, 365)
    || ' days'
    FROM DUAL;

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

Maybe you are looking for

  • How to pass html input as record

    Hi to all, i've a form with 5 input type text and i would like to pass it to a procedure as record, it's possible? tnx

  • House Bank Creation-F110 APP

    Hi, I have created one house bank for one bank and different Account IDS for each bank account that is Current and CC account. In FBZP transaction code, system is not allowing to enter the same house bank number more than once, in which case all the

  • Query regarding display values

    Hi, I Have a Table with column name as agent_name guest billing i have to display report as                                             2010                      2009 Agent_name           guest        billing        guest     billing abc             

  • Grey Screen restart w/o Lion disk?

    I have an iMac which was upgraded to Lion some time ago. Due to user error, I have the grey screen of death. Am I able to reboot from my Snow Leopard install disk? Lion install was done from a download, and I don't have a startup disk for it.

  • Error when generating text environment

    I am using the ESS Address iViews for several countries. All coutries work fine, except Address for Netherlands, which crashes when user tries to update the address, see error message in Portal below. I also get a ST22 error Error when generating tex