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: 

Calculation of date difference

Former Member
0 Kudos
1,231

How to calculate the difference between two dates? Is there any standard function module available?

1 ACCEPTED SOLUTION

varma_narayana
Active Contributor
0 Kudos
298

Hi...

<b>to Calculate the No of working days between 2 dates</b>

CALL FUNCTION 'RKE_SELECT_FACTDAYS_FOR_PERIOD'

EXPORTING

i_datab = date1

i_datbi = date2

i_factid = 'GB'

TABLES

eth_dats = l_it_dat.

Also check

<b>Check the following code for subtract years/months/date from particular date:</b>

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.

<b>call function 'FIMA_DAYS_AND_MONTHS_AND_YEARS'</b>

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.

reward if Helpful.

11 REPLIES 11

Former Member
0 Kudos
298

Hi Papiya,

You can use the following FM

CALL FUNCTION 'HR_HK_DIFF_BT_2_DATES'

EXPORTING

DATE1 = higher date

DATE2 = lower date

OUTPUT_FORMAT = '02'

IMPORTING

DAYS = W_DAYS

EXCEPTIONS

INVALID_DATES_SPECIFIED = 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.

Based on output_format you can get years/days/months combination

OUTPUT_FORMAT = '02' will give you the days only as requested

Other function modules are also available like

FIMA_DAYS_AND_MONTHS_AND_YEARS

FIMA_DAYS_BETWEEN_TWO_DATES

Reward if helpful

Thanks.

Former Member
0 Kudos
298

Hi papiya,

1. HR_HK_DIFF_BT_2_DATES

2. This will give difference in Days, Months and also in years.

regards,

amit m.

Former Member
0 Kudos
298

hi Papiya,

Use the Function Module ISHMED_CALC_DATE_TIME_DIFF

Import parameters Value

I_BEGDT 01.01.2007

I_BEGTM 00:00:00

I_ENDDT 01.08.2007

I_ENDTM 00:00:00

Changing parameters Value

CR_ERRORHANDLER

Export parameters Value

E_DIFF_DAY 212

E_ENDDT_EARLY

E_RC 0

U can find the time diff also from this function module.

OR OR OR OR

you Use SD_DATETIME_DIFFERENCE

DATE1 01.01.2007

TIME1 12:00:00

DATE2 01.08.2007

TIME2 10:00:00

Export parameters Value

DATEDIFF 211

TIMEDIFF 22

EARLIEST 1

Reward Points If Use Full

Thanks & Regards.

Shiva

varma_narayana
Active Contributor
0 Kudos
299

Hi...

<b>to Calculate the No of working days between 2 dates</b>

CALL FUNCTION 'RKE_SELECT_FACTDAYS_FOR_PERIOD'

EXPORTING

i_datab = date1

i_datbi = date2

i_factid = 'GB'

TABLES

eth_dats = l_it_dat.

Also check

<b>Check the following code for subtract years/months/date from particular date:</b>

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.

<b>call function 'FIMA_DAYS_AND_MONTHS_AND_YEARS'</b>

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.

reward if Helpful.

former_member189059
Active Contributor
0 Kudos
298

<b>SD_DATETIME_DIFFERENCE</b> will work

give time1 and time2 as 00:00:01

Former Member
0 Kudos
298

Hi,

you can use the FM '/SDF/CMO_DATETIME_DIFFERENCE' for calculating the date difference. You can leave the time1 and time2 fields as BLANK during date calculation.

Also you can calculate the date and time difference using the same FM, by passing both date and time values.

Hope this helps .....

Regards,

Dilli

Former Member
0 Kudos
298

Hi,

Use the Function Module : DURATION_DETERMINE or DAYS_BETWEEN_TWO_DATES to find the date difference between two dates.

Hope this info will help you.

Rewards points if Useful.

With regards,

K K V

former_member189631
Active Contributor
0 Kudos
298

Hi Papiya,

<b>*</b>Yes, FM is available to calulate date Difference.

<b>*</b>Use this FM to get Difference BW two dates:

<b>FI_PSO_DAYS_MONTHS_YEARS_GET</b>

-


Import parameters Value

-


I_DATE_FROM 12.12.2006

I_DATE_TO 21.12.2008

_______________________________________________

-


Export parameters Value

-


E_DAYS 740

E_MONTHS 25

E_YEARS 3

________________________________________________

Regards,

<b>Ram</b>.

Former Member
0 Kudos
298

Hi Papiya,

Go to SE37 and Search with the string dates u'll find many function modules which can give the difference in periods format, days format etc... Pick out the FM that suits your requirement the best..

Regards,

Sai

Former Member
0 Kudos
298

Hi,

Use the function module

HR_SGPBS_YRS_MTHS_DAYS

0 Kudos
298

Check this fm

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.

This returns no of Days, Month and Year as a difference in two dates.

ashish