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

Difference Bitween Two Days

Former Member
0 Likes
1,229

Hii ,

I want to find out difference bitween two days

supose example

01/05/2008 and 15/05/2008

the difference bitween these two days is 15

can some one provide me the required Function module

6 REPLIES 6
Read only

Former Member
0 Likes
1,008

Hello,

Use this FM


DATA: G_F_DIFF TYPE I.
  CALL FUNCTION 'DAYS_BETWEEN_TWO_DATES'
       EXPORTING
            I_DATUM_BIS             = G_T_PURO-AEDAT    " End date 
            I_DATUM_VON             = G_T_EBAN-BADAT " Start Date
       IMPORTING
            E_TAGE                  = G_F_DIFF
       EXCEPTIONS
            DAYS_METHOD_NOT_DEFINED = 1
            OTHERS                  = 2.

Cheers,

Vasanth

Read only

Former Member
0 Likes
1,008

hi,

do this way ..

HR_HK_DIFF_BT_2_DATES

or you can use FIMA_DAYS_AND_MONTHS_AND_YEARS

See the below code for ur refrence:


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.
 

Regards,

Santosh

Read only

Former Member
0 Likes
1,008

hi,

You can even define a variable of type I and just subtract both dates.


days = date2 - date1. 

Regards,

Santosh

Read only

Former Member
0 Likes
1,008

Hi,

You don't need a funciton module. Provided the two fields are held as type DAT you just need to subtract one field from the other;


DAYS = W_DATE1 - W_DATE2.

Regards,

Nick

Read only

Former Member
0 Likes
1,008

Hi,

Use Function module SD_DATETIME_DIFFERENCE to get Difference Bitween Two Days

FUNCTION SD_DATETIME_DIFFERENCE.

*"----


""Lokale Schnittstelle:

*" IMPORTING

*" VALUE(DATE1) TYPE D

*" VALUE(TIME1) TYPE T

*" VALUE(DATE2) TYPE D

*" VALUE(TIME2) TYPE T

*" EXPORTING

*" VALUE(DATEDIFF) TYPE P

*" VALUE(TIMEDIFF) TYPE P

*" VALUE(EARLIEST) TYPE C

*" EXCEPTIONS

*" INVALID_DATETIME

So the type D is datum (so those parameters are dates), type T is for time, type P is for number

You can also have alook at these Function modules

SD_DATETIME_DIFFERENCE

DAYS_BETWEEN_TWO_DATES

MONTHS_BETWEEN_TWO_DATES..

Regards,

Raj.

Read only

Former Member
0 Likes
1,008

Hi,

The FM 'HR_AUPBS_MONTH_DAY'

gives us a code that helps you calculate the no of days between two dates.

Jus look at the following code

IF D1 > D2.

D3 = ( D1 - D2 + 1 ) * -1.

ELSE.

D3 = D2 - D1 + 1.

ENDIF.

d1 n d2 are the two dates.

check

https://forums.sdn.sap.com/click.jspa?searchID=11811178&messageID=3247295

Regards

Kiran Sure