cancel
Showing results for 
Search instead for 
Did you mean: 

Subtract Business Days from a Date

carmine1
Explorer
0 Kudos
295

In Crystal Reports, how to subtract a number of business days (Monday through Friday) from an input date?

For example, October 29, 2024 - 16 business days = October 7, 2024

Accepted Solutions (0)

Answers (3)

Answers (3)

Ranjan__Panda
Explorer

Hi,

Use this function module to subtract a number of business days (Monday through Friday) from an input date.

DATA: lv_date TYPE sy-datum.  "Input Date
DATA: lv_business_days TYPE i VALUE 10. "Number of business days to subtract
DATA: lv_new_date TYPE sy-datum. "Output Date

CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'
EXPORTING
date = lv_date     "October 29, 2024
days = lv_business_days    "16 business days
months = 0
years = 0
signum = '-'
IMPORTING
calc_date = lv_new_date.  "October 7, 2024

WRITE: / lv_date, lv_new_date.

 

Regards,
Ranjan Panda

carmine1
Explorer
0 Kudos
Thanks! I will give this a try.
ido_millet
Active Contributor
0 Kudos
DonWilliams
Active Contributor
0 Kudos

In ALL software if you hit the F1 key you will get the Help file attached.

Then search for "DateAdd (intervalType, nIntervals, startDateTime)"

Or something similar should work for you

carmine1
Explorer
0 Kudos

I know very well how to DateAdd. But that does not help with an elegant way to adjust for business days (weekdays) only.  For example, November 15, 2024 minus 127 weekdays = WhatDate?

carmine1
Explorer
0 Kudos

I found this solution elsewhere, however I am not certain that it always yields the correct result: DATEADD('d', -7*(no_of_days / 5) - no_of_days % 5, start_date)

carmine1
Explorer
0 Kudos
I found this solution elsewhere, however I am not certain that it always yields the correct result: DATEADD('d', -7*( no_of_days/ 5) - no_of_days mod 5, starting_date)