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

Subtracting two dates

Former Member
0 Likes
967

Hi all,

is there a Function Module for subtracting two dates.

i.e.

Date1 = 20060629

Date2 = 20060703

the answer is 4 days.

Thanks in advance.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
855

hi,

PARAMETER:p_date1 TYPE dats,
          p_date2 TYPE dats.
 
DATA:lv_diff TYPE i,
     lv_no_date type i.
 
 
CALL FUNCTION <b>'DAYS_BETWEEN_TWO_DATES'</b>
  EXPORTING
    i_datum_bis             = p_date1
    i_datum_von             = p_date2
  IMPORTING
    e_tage                  = lv_diff
  EXCEPTIONS
    days_method_not_defined = 1
    OTHERS                  = 2.
IF sy-subrc <> 0.
  WRITE:/ 'Error'.
ELSE.
  WRITE:/ lv_diff.
ENDIF.
 
if lv_diff < 0.
lv_diff = lv_diff * -1.
endif.
 
lv_no_date = lv_diff - 1.

Check this thread out

Reward it it helps,

Santosh

7 REPLIES 7
Read only

Former Member
0 Likes
856

hi,

PARAMETER:p_date1 TYPE dats,
          p_date2 TYPE dats.
 
DATA:lv_diff TYPE i,
     lv_no_date type i.
 
 
CALL FUNCTION <b>'DAYS_BETWEEN_TWO_DATES'</b>
  EXPORTING
    i_datum_bis             = p_date1
    i_datum_von             = p_date2
  IMPORTING
    e_tage                  = lv_diff
  EXCEPTIONS
    days_method_not_defined = 1
    OTHERS                  = 2.
IF sy-subrc <> 0.
  WRITE:/ 'Error'.
ELSE.
  WRITE:/ lv_diff.
ENDIF.
 
if lv_diff < 0.
lv_diff = lv_diff * -1.
endif.
 
lv_no_date = lv_diff - 1.

Check this thread out

Reward it it helps,

Santosh

Read only

Simha_
Product and Topic Expert
Product and Topic Expert
0 Likes
855

Hi,

simply u can use ans = date2- date1.

It helps...

Cheers,

SImha.

Read only

Former Member
0 Likes
855

Hi ,

you can use this FM.

HR_HK_DIFF_BT_2_DATES

Regards,

Sumit.

Read only

Former Member
0 Likes
855

hi,

you can use the function module

HR_HK_DIFF_BT_2_DATES

Reward if helps.

Thanks,

krishnakuamr

Read only

Former Member
0 Likes
855

if u subtract directly 2 date variables to an integer variable it will give u the difference in days only.

example :

x = date1 - date2. where x is an interger.

Read only

Former Member
0 Likes
855

Hi,

Try this function module.

"HR_HK_DIFF_BT_2_DATES"

For this DATE1 should be greater that DATE2.

Check the following code...

DATA: lw_date1 TYPE p0001-begda,

lw_date2 TYPE p0001-begda,

lw_date TYPE p0347-scrdd.

lw_date1 = sy-datum.

lw_date2 = '12.12.2004'.

CALL FUNCTION 'HR_HK_DIFF_BT_2_DATES'

EXPORTING

date1 = lw_date1

date2 = lw_date2

OUTPUT_FORMAT = '02'

IMPORTING

days = lw_date.

Thanks and regards,

Bharat Kuamr Reddy.V

Read only

Former Member
0 Likes
855

Hi check the following ,

http://www.sapdb.org/7.4/htmhelp/d1/cc7498bb4111d2a97100a0c9449261/content.htm

Please reward for the same.