2008 Sep 26 1:01 AM
hi experts,
Can anyone help in writing the method for the below requirement.
Ex:
OldDate: 03/10/1992
Current Date:09/24/2008
Calculation : (difference between the two dates) / 365 = 6042 / 365 = 16.55 (rounded to the second decimal place)
I tried with the below code. Not sure if it is right.
METHOD NoOfDays.
DATA: employerServiceDate TYPE sy-datum,
noofdays TYPE i,
l_year TYPE char4,
l_mm TYPE char2,
l_dd TYPE char2,
l_diff_days TYPE d.
CLEAR :l_year,l_mm,l_dd,values,l_diff_days,employerServiceDate.
l_mm = employerServiceDate(2).
l_dd = employerServiceDate+3(2).
l_year = employerServiceDate+6(4).
CONCATENATE l_year l_mm l_dd INTO employerServiceDate.
l_diff_days = (sy-datum - employerServiceDate)/365.
values = l_diff_days.
ENDMETHOD.
Thanks
Ramani
2008 Sep 26 2:23 AM
Hi Ramani,
What is your expected output?
16.55 should be ___?___ .
Regards,
R.Nagarajan.
2008 Sep 26 3:50 AM
2008 Sep 26 4:10 AM
Other Way would be,
DATA: lv_old TYPE datum VALUE '19920310',
lv_curr TYPE datum VALUE '20080924',
lv_diff LIKE p0347-scrdd,
lv_bal TYPE p DECIMALS 2.
lv_diff = lv_curr - lv_old.
lv_bal = lv_diff / 365.
WRITE:/ lv_bal.
2008 Sep 26 3:36 AM
See the results of this code.
DATA: lv_old TYPE datum VALUE '19920310',
lv_curr TYPE datum VALUE '20080924',
lv_diff LIKE p0347-scrdd,
lv_bal TYPE p DECIMALS 2.
CALL FUNCTION 'HR_HK_DIFF_BT_2_DATES'
EXPORTING
date1 = lv_curr
date2 = lv_old
output_format = '02'
IMPORTING
days = lv_diff
EXCEPTIONS
invalid_dates_specified = 1
OTHERS = 2.
lv_bal = lv_diff / 365.
WRITE:/ lv_bal.
Aman
2010 Mar 30 5:15 AM