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 Difference without sunday

Former Member
0 Likes
486

Hi,

I want to count days between two date. for that pupose there is a FM SD_DATETIME_DIFFERENCE but it calculates sundays also. My requirment is only working days should be calculate (weekly off is sunday). if there is any FM for that plz tell me.

Thanks in Advance.

Jitendra

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
459

Hi,

1st calculate Total difference in days including weekends

*For calculating days excluding weekends

CALL FUNCTION 'DAYS_BETWEEN_TWO_DATES'

EXPORTING

i_datum_bis = wa_item_hist-end_date

i_datum_von = wa_item_hist-start_date

IMPORTING

e_tage = l_diff_dates

EXCEPTIONS

days_method_not_defined = 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.

Then calcualte days of weekends within the period range

IF NOT wa_item_hist-start_date IS INITIAL AND

NOT wa_item_hist-end_date IS INITIAL.

CALL FUNCTION 'CATSXT_GET_HOLIDAYS'

EXPORTING

im_personnel_number = '00000000'

im_begin_date = wa_item_hist-start_date

im_end_date = wa_item_hist-end_date

im_get_weekend_days = 'X'

IMPORTING

ex_holidays = i_holiday_tab.

DELETE i_holiday_tab WHERE freeday = ' '.

DESCRIBE TABLE i_holiday_tab LINES l_lines.

IF l_diff_dates NE 1.

l_diff_dates = l_diff_dates - l_lines.

ENDIF.

ENDIF.

Best regards,

Prashant

3 REPLIES 3
Read only

Former Member
0 Likes
460

Hi,

1st calculate Total difference in days including weekends

*For calculating days excluding weekends

CALL FUNCTION 'DAYS_BETWEEN_TWO_DATES'

EXPORTING

i_datum_bis = wa_item_hist-end_date

i_datum_von = wa_item_hist-start_date

IMPORTING

e_tage = l_diff_dates

EXCEPTIONS

days_method_not_defined = 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.

Then calcualte days of weekends within the period range

IF NOT wa_item_hist-start_date IS INITIAL AND

NOT wa_item_hist-end_date IS INITIAL.

CALL FUNCTION 'CATSXT_GET_HOLIDAYS'

EXPORTING

im_personnel_number = '00000000'

im_begin_date = wa_item_hist-start_date

im_end_date = wa_item_hist-end_date

im_get_weekend_days = 'X'

IMPORTING

ex_holidays = i_holiday_tab.

DELETE i_holiday_tab WHERE freeday = ' '.

DESCRIBE TABLE i_holiday_tab LINES l_lines.

IF l_diff_dates NE 1.

l_diff_dates = l_diff_dates - l_lines.

ENDIF.

ENDIF.

Best regards,

Prashant

Read only

S0025444845
Active Participant
0 Likes
459

Hi Jitendra,

You can use the following FM

CALL FUNCTION 'RKE_SELECT_FACTDAYS_FOR_PERIOD'

EXPORTING

i_datab = date1

i_datbi = date2

i_factid = 'GB'

TABLES

eth_dats = l_it_dat.

In i_factid you have to pass factory Id like for india 'IN' or some other coutnry

n pass two dates you will get only working days in between those two dates

according to that calender

regards,

Sudha

reward points if helpful

Read only

Former Member
0 Likes
459

answered