Application Development 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: 

Function module to get the difference of dates ..

Former Member
0 Kudos

Hi ,

Can somebody pls help me with the function module to get the difference between two dates?

I need to find the difference value and delete records if >1.

Thanks in advance.

Regds,

Leeza.

11 REPLIES 11

Former Member
0 Kudos

Use SD_DATETIME_DIFFERENCE

Ashish

Former Member
0 Kudos

Thnx for the help Ashish.It was indeed very helpful info.

But I dont have the time parameter.

Any other FM to help out with input as only the date values and get the difference.

Regds,

Leeza.

0 Kudos

Leeza, it's ok if u don't have time, just hardcode 240000 in both the time fields.

Ashish

0 Kudos

Leeza,

Try <b>DAYS_BETWEEN_TWO_DATES

MONTHS_BETWEEN_TWO_DATES</b>.

Thanks

Kam

former_member188685
Active Contributor
0 Kudos

Hi thif FM needs time input also.

SD_DATETIME_DIFFERENCE

regards

vijay

Former Member
0 Kudos

Hi Leeza,

This FM.

HR_99S_INTERVAL_BETWEEN_DATES

The above FM is comprehensive.

it will give much information.

difference in

-


days

weeks

months

and years

-


Regards,

Amit M.

Message was edited by: Amit Mittal

Message was edited by: Amit Mittal

Former Member
0 Kudos

Thanks Kam...

MONTHS_BETWEEN_TWO_DATES is not retrieving any value when I specify only the dates.

What should be the 'I_KZ_INCL_BIS' value be?

0 Kudos

Leeza,

When I tested the FM in my Program, it is <b>working</b>!!!!!

Note that the Two Input Dates are to be in the format of <b>DATS</b> type (Eg: <b>vimimv-dmibeg</b>).

U can want the Day which u have specified in the parameter I_DATUM_BIS (eg: 20050101) to be included for

the calculation , then put X in the parameter I_KZ_INCL_BIS.

Sample Code :

report zkam01.

data:

<b>sav_nlaufz like rf60v-nlaufz,

date1 type vimimv-dmibeg,

date2 type vimimv-dmiend.</b>

date1 = '20050101'.

date2 = '20051001'.

call function 'MONTHS_BETWEEN_TWO_DATES'

exporting

i_datum_von = date1

i_datum_bis = date2

i_kz_incl_bis = 'X'

importing

e_monate = sav_nlaufz.

write:

date1,

/ date2,

/ sav_nlaufz.

Please allot points if the problem is solved.

Thanks

Kam

Message was edited by: Kam

Former Member
0 Kudos

Hi,

You dont need function module to get difference between two dates. You can simply subtract and get days.

See the following example,

DATA: gv_date1 LIKE sy-datum,

gv_date2 LIKE sy-datum,

gv_days TYPE i.

gv_date1 = '20051125'.

gv_date2 = '20051124'.

IF gv_date1 GE gv_date2.

gv_days = gv_date1 - gv_date2.

ELSE.

gv_days = gv_date2 - gv_date1.

ENDIF.

WRITE gv_days.

Hope this helps..

Sri

Message was edited by: Srikanth Pinnamaneni

Former Member
0 Kudos

Hi,

Sample code for the function module you want.

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,

Sailaja.

Dont forget to reward points, if answer helps you.

Former Member
0 Kudos

Hi Leeza,

You don't need a function module to do that. Here is a simple logic.


LOOP AT itab.
  v_number_of_days = itab-date2 - itab-date1.
  IF v_number_of_days > 1.
    DELETE itab.
  ELSE.
*-- Do something else.
  ENDIF.
ENDLOOP.