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: 

calculate days

Former Member
0 Kudos

hii,

can anybody tell how to calculate the no. of days after subtracting two dates?

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

try this .

Data:

z_date1 type sy-datum,

z_date1 type sy-datum,

z_day type i.

z_date1 = (assign value).

z_date2 = (assign value).

z_day = z_date1 - z_date2.

write: z_day.

for further in date calculation , check

http://help.sap.com/saphelp_nw70/helpdata/en/fc/eb334a358411d1829f0000e829fbfe/content.htm

regards,

Anirban

12 REPLIES 12

milusai
Participant
0 Kudos

Use FM

HR_HK_DIFF_BT_2_DATES

Former Member
0 Kudos

Hi,

try this .

Data:

z_date1 type sy-datum,

z_date1 type sy-datum,

z_day type i.

z_date1 = (assign value).

z_date2 = (assign value).

z_day = z_date1 - z_date2.

write: z_day.

for further in date calculation , check

http://help.sap.com/saphelp_nw70/helpdata/en/fc/eb334a358411d1829f0000e829fbfe/content.htm

regards,

Anirban

Former Member
0 Kudos

hi..

Use FM 'HR_HK_DIFF_BT_2_DATES' and pass

OUTPUT FORMAT = '03'.

U will get no of days...!!

regards,

Padma.

Former Member
0 Kudos

Hi,

HR_HK_DIFF_BT_2_DATES : Find the difference between two dates in years, months and days.

FIMA_DAYS_AND_MONTHS_AND_YEARS : Find the difference between two dates in years, months and days.

HR_99S_INTERVAL_BETWEEN_DATES : Difference between two dates in days, weeks, months

Regards,

Swati

Former Member
0 Kudos

Hi aks,

Use FM : HR_SGPBS_YRS_MTHS_DAYS

Former Member
0 Kudos

Hi,

Use this FM 'HR_CALC_YEAR_MONTH_DAY' .

Thanks,

Phani Diwakar.

Former Member
0 Kudos

how to use this FM..

0 Kudos

DATA : v_years TYPE p0347-scryy,

v_months TYPE p0347-scrmm,

v_days TYPE p0347-scrdd.

CALL FUNCTION 'HR_HK_DIFF_BT_2_DATES'

EXPORTING

date1 = sy-datum

date2 = '20010101'

  • OUTPUT_FORMAT = '01'

IMPORTING

years = v_years

months = v_months

days = v_days

  • EXCEPTIONS

  • INVALID_DATES_SPECIFIED = 1

  • OTHERS = 2

.

IF sy-subrc = 0.

WRITE : / v_years , v_months , v_days.

ENDIF.

Edited by: Milind Mungaji on Oct 8, 2008 8:04 AM

Former Member
0 Kudos

Hi,

Its yuor choice if to use Function module or code it directly.

date1 type sy-datum,
date2 type sy-datum, 
days type i.


days = date1 - date2.
write: days.

or we can use FM "HR_99S_INTERVAL_BETWEEN_DATES".

CALL FUNCTION 'HR_99S_INTERVAL_BETWEEN_DATES'
  EXPORTING
    BEGDA           = date1
    endda           =   date2
*   TAB_MODE        = ' '
 IMPORTING
   DAYS            = days
*   C_WEEKS         =
*   C_MONTHS        =
*   C_YEARS         =
*   WEEKS           =
*   MONTHS          =
*   YEARS           =
*   D_MONTHS        =
*   MONTH_TAB       =
          .
write:/ days.

thanx.

Former Member
0 Kudos

hi

use HR_HK_DIFF_BT_2_DATES FM

pass recent date DATE1 and

previous date to DATE2

and if you want it days

pass 02 to OUTPUT_FORMAT , u ll get in YEARS(export parameter)

u ll get in year format if u pass 01 in DAYS(export parameter)

Former Member
0 Kudos

where to write this FM, showing runtime error in the begining of function,or do i need to declare something before using this FM.

Edited by: aks on Oct 8, 2008 2:16 AM

Edited by: aks on Oct 8, 2008 2:17 AM

Former Member
0 Kudos

Thanks everyone..