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

date diff

Former Member
0 Likes
1,136

what is the program for to get diff between two dates.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,074

U can just do x - y and it would give you the result in days.

ldate --->date1

ldays = ldate - sy-datum.

The above would give you the difference between two dates.

10 REPLIES 10
Read only

Former Member
0 Likes
1,075

U can just do x - y and it would give you the result in days.

ldate --->date1

ldays = ldate - sy-datum.

The above would give you the difference between two dates.

Read only

0 Likes
1,074

may i get it in following format

Ex: first date : 20006-11-20

second date: 20005-10-10

ans: 1-1-10

i want answer looikng like above.

Read only

0 Likes
1,074

hi,

[code]

data: date1 type sy-datum,

date2 type sy-datum.

data: diff type i.

diff = date1 - date2.

then use FM

'CONVERT_DATE_TO_EXTERNAL'

data: datum(10) type c.

call function 'CONVERT_DATE_TO_EXTERNAL'

exporting

date_internal = diff

importing

date_external = datum.

write:/ datum.

[\code]

Regards

Anver

Message was edited by:

Anversha s

Read only

0 Likes
1,074

hi anver

pls give how to use that function

Read only

0 Likes
1,074

Hi Madhav,

Check this code.


  CALL FUNCTION 'HR_MX_INTERVAL_BETWEEN_DATES'
      EXPORTING
        I_DATE_START                = gd_start_date
        I_DATE_END                   = gd_end_date
      IMPORTING
        E_YEARS                       = gd_years
        E_DAYS                         = gd_days
      EXCEPTIONS
        SEQUENCE_OF_DATES_NOT_VALID = 1
        ERROR_IN_CALC_OF_YEARS      = 2
        NO_ENTRY_IN_T511K           = 3
        OTHERS                      = 4.
    if sy-subrc   <> 0.
    endif.
  

Hope this will help you.

Thanks & Regards,

Siri.

null

Read only

anversha_s
Active Contributor
0 Likes
1,074

hi,

just minus the 2 dates directly.

eg:

data: date1 type sy-datum,

date2 type sy-datum.

data: diff type i.

diff = date1 - date2.

regards

Anver

Read only

Former Member
0 Likes
1,074

Hi

Please check the following FM

<b>SD_DATETIME_DIFFERENCE</b>

Read only

0 Likes
1,074

pls give code for it . i mean what i have to set.

Read only

0 Likes
1,074

HI,

check the example below

<b>

data: dat1 type sy-datum.
data: dat2 type sy-datum.
data: days like P0347-SCRDD.

dat1 = '20051212'.

dat2 = '20061212'.


CALL FUNCTION 'HR_HK_DIFF_BT_2_DATES'
  EXPORTING
    DATE1                         = dat2
    DATE2                         = dat1
   OUTPUT_FORMAT                 = '02'
 IMPORTING

  DAYS                          = days          .


Write:/ days.

</b>

REgards,

Read only

dani_mn
Active Contributor
0 Likes
1,074

HI,

Try this FM.

<b>HR_HK_DIFF_BT_2_DATES</b>

Regards,