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

Need help

Former Member
0 Likes
670

Hi all,

I am working on a program that needs to show number of days between 2 dates. When I scanned the function library, I only found a function to give you the number of years between dates. I can probably code this in ABAP but does anyone know if a function exists to do this.

Thanks ,

Praveen.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
646

yeah u have it.

data : DATE1 LIKE P0001-BEGDA,

DATE2 LIKE P0001-BEGDA,

OUTPUT_FORMAT LIKE T7HK2B-SCALC value '02',

diffYEARS LIKE P0347-SCRYY,

diffMONTHS LIKE P0347-SCRMM,

diffDAYS LIKE P0347-SCRDD.

date1 = sy-datum.

date2 = '20061201'.

CALL FUNCTION 'HR_HK_DIFF_BT_2_DATES'

EXPORTING

date1 = date1

date2 = date2

OUTPUT_FORMAT = output_format

IMPORTING

YEARS = diffyears

MONTHS = diffmonths

DAYS = diffdays

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.

write:/ 'diffdays' , diffdays.

check this .

Vijay.

5 REPLIES 5
Read only

Former Member
0 Likes
647

yeah u have it.

data : DATE1 LIKE P0001-BEGDA,

DATE2 LIKE P0001-BEGDA,

OUTPUT_FORMAT LIKE T7HK2B-SCALC value '02',

diffYEARS LIKE P0347-SCRYY,

diffMONTHS LIKE P0347-SCRMM,

diffDAYS LIKE P0347-SCRDD.

date1 = sy-datum.

date2 = '20061201'.

CALL FUNCTION 'HR_HK_DIFF_BT_2_DATES'

EXPORTING

date1 = date1

date2 = date2

OUTPUT_FORMAT = output_format

IMPORTING

YEARS = diffyears

MONTHS = diffmonths

DAYS = diffdays

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.

write:/ 'diffdays' , diffdays.

check this .

Vijay.

Read only

Former Member
0 Likes
646

Check this FM.

HR_HK_DIFF_BT_2_DATES

Also check this thread.

Regards,

Maha

Read only

arpit_shah
Contributor
0 Likes
646

hi,

its very easy,

do not require any FM

do like this,

data : diff type i.

diff = date2 - date1.

Reward if it is helpful to u.

Regards,

Arpit Shah

Read only

Former Member
0 Likes
646

Hi Suneela,

Check FM HR_99S_INTERVAL_BETWEEN_DATES

give start date & end date.

Get no of days

DAYS = ur required result.

If it is helpfull pls reward pts.

Regards

Srimanta

Read only

Former Member
0 Likes
646

Hi,

I think this is what you need.

DATA: DATE_1 LIKE SY-DATUM,

DATE_2 LIKE SY-DATUM.

DATA DAYS TYPE I.

DATE_1 = SY-DATUM.

DATE_2 = SY-DATUM + 65.

DAYS = DATE_2 - DATE_1.

WRITE:/ 'DATE_2=',DATE_2,'DATE_1=',DATE_1,'DAYS=',DAYS.

Reward points if found helpfull...

Cheers,

Chandra Sekhar.