Hi,
Try this 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.
For ur Question 2:
Check the link,
http://www.sapdevelopment.co.uk/tips/date/date_months.htm>
Hope it helps u.
Thanks&Regards,
Ruthra.R
Hi Ravi,
If your requirement is to get just days between two days irrespective of factory calendar then you can do the following,
DATA: lv_date1 LIKE sy-datum '20050925',
lv_date2 LIKE sy-datum '20050930',
lv_days TYPE i.
lv_days = lv_date2 - lv_date1.
WRITE: lv_days.
Also, in order to get a new date by adding or subtracting days,
DATA: lv_date LIKE sy-datum,
lv_days TYPE i.
lv_days = 5.
lv_date = sy-datum + lv_days. "Add
lv_date = sy-datum - lv_days. "Subtract
Sri
Hi,
Try this out
CALL FUNCTION <b>'DATE_IN_FUTURE'</b> EXPORTING anzahl_tage = import_datum = * IMPORTING * EXPORT_DATUM_EXT_FORMAT = * EXPORT_DATUM_INT_FORMAT =
.
In <b>anzahl_tage </b> parameter u can give 30 if u want 30 days later and if u want -30 days then u can specify the same sot hat u will be getting both the future and past days.
<b>Days b/w two dates</b>
DATA: DATE_1 LIKE SY-DATUM, DATE_2 LIKE SY-DATUM. DATA DAYS TYPE I. DATE_1 = SY-DATUM. DATE_2 = SY-DATUM + 65. DAYS = DATE_2 - DATE_1. WRITE:/ 'DATE_2=',DATE_2,'DATE_1=',DATE_1,'DAYS=',DAYS.
Run this code and then you will understand.
Also
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
Hope this helps.
Kindly reward points for the answer which helped u.
Hi Ravi
1) If you want to know the days between two date:
CALL FUNCTION 'DAYS_BETWEEN_TWO_DATES'
EXPORTING
i_datum_bis = date_in
i_datum_von = date_out
i_kz_excl_von = '0'
i_kz_incl_bis = '0'
i_kz_ult_bis = ' '
i_kz_ult_von = ' '
i_stgmeth = '2'
i_szbmeth = '0'
IMPORTING
e_tage = days
EXCEPTIONS
days_method_not_defined = 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.
Infact:
i_szbmeth = 1 =>
GERMAN CALCULATION OF INTEREST METHOD
i_szbmeth = 2 => GREGORIAN CALENDAR
i_szbmeth = 3 =>GREGORIAN CALENDAR WITHOUT INTERCALARY DAYS
2) You don't need to use a particolar fm to get a day by adding or substracting a nuber of days. Infact the date is stored using an absolute format: YYYYMMDD.
So you can only use a data type of days number:
DATA: DAYS TYPE I
DATA: DATE_IN TYPE SY-DATUM,
DATE_OUT TYPE SY-DATUM.
DATE_OUT = DATE_IN +/- DAYS.
Max
Message was edited by: max bianchi
Message was edited by: max bianchi
Add comment