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

how to get difference between two dates.

abhijeet_mukkawar
Active Contributor
0 Likes
792

hi all,

i want to retrieve difference between two dates in working hours(excluding holidays and weekends as per US calender).

Could u please help?

Regards,

7 REPLIES 7
Read only

Former Member
0 Likes
761

Hi,

SD_DATETIME_DIFFERENCE is the FM.

Best regards,

Prashant

Read only

0 Likes
761

use fm...

<b>SD_CALC_DURATION_FROM_DATETIME</b>

Read only

0 Likes
761

hi prashant,

but i want the difference excluding holidays and weekends. SD_DATETIME_DIFFERENCE will not do that.

Read only

0 Likes
761

hi prashant,

thanks.

but i want the difference excluding holidays and weekends. SD_DATETIME_DIFFERENCE will not do that.

Read only

0 Likes
761

Hi abhijeet,

(This will exclude weekends)

1. DATE_CHECK_WORKINGDAY

This is one useful FM

2. Try this code (just copy paste)

IT DOES EXACTLY WHAT U REQUIRE.

REPORT abc.

data : num type i.

parameters : frdate type sy-datum default '20051216'.

parameters : todate type sy-datum default '20051221'.

perform getinfo using frdate todate changing num.

break-point.

&----


*& Form getinfo

&----


  • text

----


FORM getinfo USING fromdate todate CHANGING numofdays type i.

DATA : d TYPE sy-datum.

d = fromdate - 1.

DO.

d = d + 1.

IF d > todate.

EXIT.

endif.

CALL FUNCTION 'DATE_CHECK_WORKINGDAY'

EXPORTING

date = d

factory_calendar_id = '01'

message_type = 'I'

EXCEPTIONS

date_after_range = 1

date_before_range = 2

date_invalid = 3

date_no_workingday = 4

factory_calendar_not_found = 5

message_type_invalid = 6

OTHERS = 7.

IF sy-subrc = 0.

numofdays = numofdays + 1.

write 😕 d.

ENDIF.

ENDDO.

ENDFORM. "getinfo

I hope it helps.

Regards,

Amit M.

Read only

Former Member
0 Likes
761

I am not sure of any specific function for the same but you can use the below logic.

ldat1 = first date

ldat2 = second date.

ldat = ldat1 - 1.

do while ldat <= ldat2.

ldat = ldat + 1.

check holiday.

check Sat or Sunday using SY-FDAYW.

lday = lday + 1.

enddo.

lhrs = lday * 24.

Regards

Anurag

Read only

Lakshmant1
Active Contributor
0 Likes
761

Hi Abhijeet,

Check FM's RKE_SELECT_FACTDAYS_FOR_PERIOD, FIMA_DAYS_AND_MONTHS_AND_YEARS and

HR_HK_DIFF_BT_2_DATES

Hope this helps

Thanks

Lakshman