Find year,month & day between dates

Hi,
   I need to find a number of years, months & day between a given dates. For example If a employee joined on 31.01.2003 and left on 01.06.2006, I need to find in between how many years, months & days he has worked. Is there any function module available .

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.
Using teh abiove u can get difference but when u pass previous year u wont get the exact.
There is no seperate FM for this, u have to use three FM.
If possible using these three FM code u can create an FM.
<b>For years and months between two days:</b>
DATA:   EYEARS  LIKE VTBBEWE-ATAGE.
PARAMETERS: FROMDATE LIKE PREL-BEGDA,
                 TODATE   LIKE PREL-BEGDA DEFAULT SY-DATUM.
CALL FUNCTION 'COMPUTE_YEARS_BETWEEN_DATES'
  EXPORTING
    first_date                        = fromdate
*   MODIFY_INTERVAL                   = ' '
    second_date                       = todate
IMPORTING
   YEARS_BETWEEN_DATES               =  EYEARS
* EXCEPTIONS
*   SEQUENCE_OF_DATES_NOT_VALID       = 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.
Write:/ eyears.
DATA:       EMONTHS LIKE VTBBEWE-ATAGE.
PARAMETERS: FROMDATE LIKE SY-DATUM,
            TODATE   LIKE SY-DATUM
DEFAULT SY-DATUM.
CALL FUNCTION 'MONTHS_BETWEEN_TWO_DATES'
  EXPORTING
    i_datum_bis         = fromdate
    i_datum_von         = todate
*   I_KZ_INCL_BIS       = ' '
IMPORTING
   E_MONATE            = emonths
write:/ emonths
CALL FUNCTION 'DAYS_BETWEEN_TWO_DATES'
EXPORTING
I_DATUM_BIS = x_faede-zfbdt
I_DATUM_VON = p_fdat
I_KZ_EXCL_VON = '0'
I_KZ_INCL_BIS = '0'
I_KZ_ULT_BIS = ' '
I_KZ_ULT_VON = ' '
I_STGMETH = '0'
I_SZBMETH = '1'
IMPORTING
E_TAGE = dias_v.
IF SY-SUBRC <> 0.
ENDIF.
x_faede-zfbdt -> 20050915
p_fdat -> 20050811
dias_v = 4
try this and let me know.
Message was edited by:
        Judith Jessie Selvi

Similar Messages

  • 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

  • Year , Month & Day from Date.

    Hi HANA experts,
      Do help me to resolve this issue
    How can we extract or fetch year from the date.i went through some of the SCN blogs.where they create calculation views...but the steps are not that clear to me.
    can anyone please explain??
    My scenario is :
    I have date field in ANALYTIC VIEW which i have fetched from ECC  tables.
    now i need to get  the year  wise month wise and day wise reports. so what steps i should do in calculation view to get that??
    thanks
    Neeraja

    there is no ECC under SAP...as we are using suite on HANA fro AWS.and there is no restriction done by the basis till now...
    as we are new to these unable to trouble shoot things easily.
    thanks for your reply..

  • How to add a date(Year, Month, Day) table in OBIEE Administrator

    Hi,
    I am new to this tool, we are developing a HR report for emp on leave or absentees. we have data since 1982 in our tables. we want to have a date table and dimension where we can give have a hierarchy for year, month, day, so that we can design our dashboards based on time. how we can do that in OBIEE Administrator and can we do it in warehouse builder as well, if so, how. ( we have a column for date in the table by name 'leave start date' and 'leave end date', can we use this and create our own table with year month and day as separate columns).
    Thanks.

    hi,
    Using date column u can create time dim in BMM layer
    Create a new logical table and pull your date column to this table
    Next,create following columns
    Refer http://www.rittmanmead.com/2007/04/30/obi-ee-time-dimensions-and-time-series-calculations
    leave start date
    Year level :Extract(year from date_column)
    Month and year level:CAST (Extract(month from fact_date_column) As CHAR(5) ) || CAST (Extract(yearfrom fact_date_column) As CHAR(5) )
    Mon-YYYY: EVALUATE('TO_CHAR(%1,%2)' AS CHARACTER ( 30 ), "Development".""."sample sales"."Dim - leave Date"."REPORT_DATE", 'MON-YY')
    YYYY-MM : CAST ( EXTRACT( YEAR FROM "sample sales".""."sample"."Dim - Report Date"."LEAVE_DATE") AS CHARACTER ( 4 )) || '/' || CASE WHEN EXTRACT( MONTH FROM "sample sales".""."sample"."Dim - Report Date"."LEAVE_DATE") BETWEEN 10 AND 12 THEN CAST ( EXTRACT( MONTH FROM "sample sales".""."sample"."Dim - Report Date"."LEAVE_DATE") AS CHARACTER ( 2 )) ELSE '0' || CAST ( EXTRACT( MONTH FROM "sample sales".""."sample"."Dim - Report Date"."LEAVE_DATE") AS CHARACTER ( 1 )) END
    Year Quater :: EVALUATE('TO_CHAR(%1,%2)' AS CHARACTER ( 6 ), "sample sales".""."sample"."Dim -Leave Date"."REPORT_DATE", 'YYYY') || '0' || EVALUATE('TO_CHAR(%1,%2)' AS CHARACTER ( 6 ), "sample sales".""."sample"."Dim -Leave Date"."REPORT_DATE", 'Q')
    Day: EXTRACT(DAY FROM DATE_COLUMN)
    Thanks,
    Saichand.v

  • Date difference in years,month,days should consider Leap Year

    I would like to know how to compute the difference between two Date, and get the difference in years,months,days, PS. Should include New Year
    Eg Date1 : 01/01/2000
    Date2: 01/01/2005
    Diff: years=5, months=0 days=1 for a leap year is included'2004'

    I would like to know how to compute the difference
    between two Date, and get the difference in
    years,months,days, PS. Should include New Year
    Eg Date1 : 01/01/2000
    Date2: 01/01/2005
    Diff: years=5, months=0 days=1 for a leap year is
    included'2004'If any program I was using gave me that result, I would consider it a bug.

  • 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

  • How to count the days between Date Range using OO ABAP?

    hi experts,
            i want to count the days between Date Range using OO ABAP for that  which class and method  can i use?.
    Thanks,
    Mahesh.

    Not sure I understand the requirement for it to be OO, but you could always write your own (i.e. use this):
    REPORT zz_date_diff.
    CLASS date_diff DEFINITION.
      PUBLIC SECTION.
        METHODS diff IMPORTING     i_date_fm TYPE d
                                   i_date_to TYPE d
                     EXPORTING     e_days    TYPE i.
    ENDCLASS."
    CLASS date_diff IMPLEMENTATION.
      METHOD diff.
        e_days = i_date_to - i_date_fm.
      ENDMETHOD."
    ENDCLASS."
    DATA: g_ref TYPE REF TO date_diff,
          g_days  TYPE i,
          g_date_fm  TYPE d VALUE '20080101',
          g_date_to  TYPE d VALUE '20090101'.
    START-OF-SELECTION.
      CREATE OBJECT g_ref.
      CALL METHOD g_ref->diff
        EXPORTING
          i_date_fm = g_date_fm
          i_date_to = g_date_to
        IMPORTING
          e_days    = g_days.
      WRITE g_days.

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

  • Release Date for Albums Year, MONTH DAY

    Why can't I enter the release date for albums (Year month and day)?   Itunes has a field for year but that's it.    I would have loved to be at the meeting where it was discussed.
    "Year, month and day? why the heck would any want that?"
    "Well a lot of us want to see our albums in chronological order and you can't do that with just the year, many albums come out every year"
    "Blah Blah Blah, music is just to dance to, no one cares about dates, besides it would four extra digit fields in each entry"
    But seriously, I would think that Itunes would aspire to be THE program for music lovers.
    Instead of being able to just enter the release dates I have had to come up with my own work around.  I put a the release date in the format yyyymmdd in fromt of each title and then sort by titles.
    Now all of my Beatle albums finally show up in chronological order by release date.   But why should I have to massage the data like this.   I can't imagine what goes on at Itunes planning  sessions.  I'm very unhappy about the loss of cover flow but that's another story.

    I'm glad to hear that I am not the only one who sees this as a problem.  And another Beatles fan too.
    This is so fundamental.  Every album has a release date and it's part of the data that is always associated with  that album.   Why did Apple look at the data available for an album and consciously decide to truncate it?
    What kind of music lover isn't aware of when albums are released?  I just don't get it.
    I like having the date yyyymmdd in front of each album.   It isn't pretty but it means the albums are chronological.   If you want, you could just put this in the sort field and leave the regular album title in the regular field.   Then the names would be right and they would sort correctly.   But again.  Why should we have to do all that? 
    Apple is busy constantly changing where the controls are on I tunes  rather than fixing something simple and important like this.
    Today I wanted to load some songs onto my ipod touch and it took me 10 minutes to figure out how to sync because the last itunes update got rid of the side bar.  
    How are you supposed to get comfortable using a product when they keep moving the controls around?   Just quit apple.   leave the controls where they are.  Add new controls if needed but stop moving them.  I know I'm ranting now but I am honestly angry and frustrated,

  • Calculating years,months & days

    Hi,
    i have to calculate the time duration in years,months and days between contract_start_date and contract_end_date
    eg: Contract_Start_Date = '17-nov-2006' and Contract_End_Date = '21-jan-2008'

    Rehman wrote:
    Hi,
    i have to calculate the time duration in years,months and days between contract_start_date and contract_end_date
    eg: Contract_Start_Date = '17-nov-2006' and Contract_End_Date = '21-jan-2008'It's not the simplest of things to work out.
    If you use the intervals it will, like any other calculation, struggle with the fact that there are different number of days in the month and leap years to take account of.
    Whilst it's simple enough to determine how many whole years have passed and how many months difference there is, the moment you start to take account of the days you become stuck because days in conjunction with months cause the day calculation to be a little more indeterminate...
    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         to_char(c_end_date,'YYYY')-to_char(c_start_date,'YYYY')
      8        -(case when to_date(to_char(c_end_date,'DD-MM')||'-1900','DD-MM-YYYY') <
      9                    to_date(to_char(c_start_date,'DD-MM')||'-1900','DD-MM-YYYY') then 1 else 0 end) as years_between
    10        ,case when to_date(to_char(c_end_date,'DD-MM')||'-1900','DD-MM-YYYY') <
    11                    to_date(to_char(c_start_date,'DD-MM')||'-1900','DD-MM-YYYY') then
    12                    12+(to_char(c_end_date,'MM')-to_char(c_start_date,'MM'))
    13         else (to_char(c_end_date,'MM')-to_char(c_start_date,'MM'))
    14         end -
    15        (case when to_date(to_char(c_end_date,'DD')||'-01-1900','DD-MM-YYYY') <
    16                   to_date(to_char(c_start_date,'DD')||'-01-1900','DD-MM-YYYY') then 1 else 0 end)
    17         as months_between
    18        ,case when to_date(to_char(c_end_date,'DD')||'-01-1900','DD-MM-YYYY') >
    19                   to_date(to_char(c_start_date,'DD')||'-01-1900','DD-MM-YYYY') then
    20              (to_char(c_end_date,'DD')-to_char(c_start_date,'DD'))
    21         else 31-(to_char(c_start_date,'DD')-to_char(c_end_date,'DD'))
    22         end as days_between_approx
    23        ,(c_end_date-c_start_date) year(4) to month as interval_yyyy_mm
    24* from t
    SQL> /
    C_START_D C_END_DAT YEARS_BETWEEN MONTHS_BETWEEN DAYS_BETWEEN_APPROX INTERVAL_YYYY_MM
    17-NOV-06 21-JAN-08             1              2                   4 +0001-02
    21-NOV-06 17-FEB-08             1              2                  27 +0001-03
    21-JUN-06 17-JUL-08             2              0                  27 +0002-01
    SQL>This example shows that a manual calculation can determine the number of years and months ok, but the days have to be approximated; and the interval answer isn't giving the same result for the months as the manual calculation because it can't take account of the days at the same time.

  • Confused - How to Calculate Number of Days Between Dates but Exclude Weekend Dates If There Hasn't Been a Weekend Update

    Hello -
    I've been tearing my hair out over this problem i'm trying to solve, probably just been staring at it too long which is making it worse -
    I have a series of open support tickets which are supposed to be updated on a daily basis, the problem is that they aren't always being updated daily.  So, the business wants to know the number of days from when a ticket was last updated and today's
    date.  I have this basic calculation and it's working fine, however now the business wants to exclude weekends from the calculation.  The other problem is that some reps DO go in on weekends and update their tickets, so sometimes there will be updates
    made on weekend dates.
    To give an example -
    Today's date is 2014-02-10 (Monday).  A ticket was last updated last Thursday, 2014-01-30.  The difference between the two dates is 11, so it's been 11 days since the ticket was last updated.  Now, if I exclude Saturdays and Sundays, then
    it's actually been 7 days since the ticket was last updated.  I'm not sure how to do this in T-SQL.
    Now, to further complicate the problem, sometimes a ticket IS updated on a Saturday or Sunday.  So, if a ticket was updated on 2014-02-02 (Sunday), then it should be counted.  Again i'm not sure how to do this. 
    What gets me is that this is probably fairly simple and i've just been staring at it too long.  In the meantime, can someone offer some guidance?
    Thanks!!

    I've adapted this from a function on my blog. you will need to add set the YourTicketTable to where ever your tickets are stored.
    CREATE
    FUNCTION [dbo].[CalcWorkDaysBetween](@StartDate
    As DateTime,@EndDate
    AS DateTime)
    RETURNS
    INT AS
    BEGIN
    SET @EndDate
    =DATEADD(DAY,1,@EndDate)
    DECLARE @Count
    AS Int= 0
    DECLARE @Date
    As Date=@StartDate
    WHILE @Date
    < @EndDate
    BEGIN
    IF (DATEPART(WEEKDAY,@Date)IN(1,7)
    OR (SELECT
    Count(*)
    FROM YourTicketTable WHERE TicketDate=@Date)=1)
    BEGIN
    SELECT @Count = @Count
    + 1
    END
    SELECT @Date=DATEADD(Day,
    1,@Date)
    END
    RETURN
    DATEDIFF(DAY,@StartDate,@EndDate)- @Count
    END
    Regards,

  • How to relate current day to date hierarchy [year - month - day] for SSRS report paramenter

    Hi there: 
      I've created a SSRS report based on OLAP cube. In this report, there is a date parameter which is used to filter out data. 
    Now , I want this report to be run and always retrieve data from previous day. I need to supply the date parameter with something
    like SQL syntax: DATEADD(dd,-1,GETDATE())  . The question is how can I do that in the MDX world? 
     thanks
     Hui
    --Currently using Reporting Service 2000; Visual Studio .NET 2003; Visual Source Safe SSIS 2008 SSAS 2008, SVN --

    Hi Hui,
    According to your description, you need to retrieve data from previous day, so you are looking for an expression in MDX which can achieve the requirement like SQL syntax: DATEADD(dd,-1,GETDATE()), right?
    As per my understanding, it easy to achieve this requirement in report level ranther than in MDX query level. You can create another hidden parameter "Date2" using the expression below.
    =DateAdd("d",-1,Parameters!Date.Value)
    Then use Date2 parameter to filter in the query.
    If don't want to create another parameter, you can use it like below.
    Year     =DatePart("yyyy",DateAdd("d",-1,Parameters!Date.Value))
    Quarter  =DatePart("qq",DateAdd("d",-1,Parameters!Date.Value))
    Month    =DatePart("mm",DateAdd("d",-1,Parameters!Date.Value))
    Week     =DatePart("ww",DateAdd("d",-1,Parameters!Date.Value))
    Besides, DateAdd function is supported in MDX, please refer to the link below.
    http://msdn.microsoft.com/en-us/library/hh510163.aspx
    If I have anything miunderstand, please point it out.
    Regards,
    Charlie Liao
    If you have any feedback on our support, please click
    here.
    Charlie Liao
    TechNet Community Support

  • How to find no. of days,subtract date -- need help 04/21/2008 - 11/05/2007

    ADAT is internally YYYYMMDD format in table.
    Should i move this field before computation ? IF SO WHAT IS THE FORMAT ,statement pls;
    G_days = ITAB10-ADAT - ITAB11-ADAT.
    04/21/2008 - 11/05/2007 ouput is 54.   ---THIS OUTPUT IS WRONG.
    Any better way of doing this.
    second value 11/05/2007 - 09/10/2007 ouput is 86
    SORT ITAB9 BY ADAT DESCENDING.
    APPEND LINES OF ITAB9 FROM 1 TO 7 TO ITAB10.
    DELETE ITAB9 INDEX 1.
    APPEND LINES OF ITAB9 FROM 1 TO 7 TO ITAB11.
    For eg. : if  02/30/2008 - 02/10/2008 -
    ouput should be 20 days..
    Edited by: Sona on Feb 21, 2008 1:36 AM
    Edited by: Sona on Feb 21, 2008 5:45 AM

    Hi,
    Check the following code:
    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.
    Regards,
    Bhaskar

  • Using Formcalc to calculate Days between Dates

    Can anyone give me a simple FormCalc script in which an end date is subtracted from a start date and the result is expressed in number of days?  I'm using LiveCycle Designer ES (not ES2).  Thank you!

    Use the following FormCalc script:
    var numDays;
    numDays = Date2Num("21/5/2012", "DD/M/YYYY") - Date2Num("19/5/2012", "DD/M/YYYY");
    For more details on FormCalc scripting, pelase refer to: http://help.adobe.com/en_US/livecycle/es/FormCalc.pdf

Maybe you are looking for

  • Problem Installing 817 on Windows 2000 with RAID Array

    I am having a problem installing Oracle under windows 2000 which has 2 x 60 GB discs configured in RAID array. When I run the setup program the cursor goes busy for about 10 seconds and returns back to normal and nothing happens !. No errors nothing.

  • Hard drive space on a pc...

    I have 2 hard drives on my pc, and 80 gig and a 250 gig. I have files and programs and stuff on both, but theres a good 125GB not being used on my 250gig. I want to use at least 100 gigs of that for backup for time machine when leopard comes out. Can

  • Using FindObjects view in a workflow?

    Hello all, could somebody provide a simple example of how to use FindObjects view in a workflow? when I try to use getView type FindObjects - I get what essentially is a view template. <Action id='0' application='com.waveset.session.WorkflowServices'

  • How I can block access to internet

    Hi, i have a computer that its connected to internet by modem, and I need to make a program in JAVA that close the access of my computer to these services of internet: http, ftp, smtp, irc. I try to do it, but I cant.... Please HELP!!!!!!!

  • Log in WLC 5508

    Hello. Someone knows what does it mean this log in the wlc 5508 with 7.5 IOS version: *apfMsConnTask_5: Oct 25 12:07:04.880: #APF-4-RCV_ACTION_FRM_WITH_CODE: apf_80211k.c:643 Received Action frame with code 4 from mobile station 4C:8D:79:CF:9B:53 Bec