Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

days_between_two_days

Former Member
0 Likes
5,092

Dear All

1. What all parameters to be passed to DAYS_BETWEEN_TWO_DAYS function module to get the no. of days between the two days.

2. Let me know the function module to get a new date by adding or substracting Number of DAYS to a date.

Please advice

ravi

Dear All

1. What all parameters to be passed to DAYS_BETWEEN_TWO_DAYS function module to get the no. of days between the two days.

2. Let me know the function module to get a new date by adding or substracting Number of DAYS to a date.

Please advice

ravi

6 REPLIES 6
Read only

Former Member
0 Likes
4,648

Hello Ravi,

You can FIMA_DAYS_BETWEEN_TWO_DATES_2 and use the parameters

I_DATUM_VON --> start date

I_DATUM_BIS --> end date

I_STGMETH --> 2 (this parameter is to determin the number of days in a year. I advise to use <b>2</b>)

Good luck,

Ronald.

Read only

Former Member
0 Likes
4,648

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,

<u>http://www.sapdevelopment.co.uk/tips/date/date_months.htm</u>

Hope it helps u.

Thanks&Regards,

Ruthra.R

Read only

Former Member
0 Likes
4,648

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

Read only

Former Member
0 Likes
4,648

Hi,

Use MONTH_PLUS_DETERMINE for your second question.

Please reward points if this explanation is useful.

Regards,

Siva

Read only

Former Member
0 Likes
4,648

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.

Read only

Former Member
0 Likes
4,648

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