Symptom
- How to calculate the number of business days?
- How to find the number of business days from: Monday to Friday, in a date range, in Crystal Reports?
Environment
- SAP Crystal Reports 2013
- SAP Crystal Reports 2016
- SAP Crystal Reports 2020
Resolution
- To calculate the number of Business Days, create a formula using the function DateDiff. Below is an example of a formula that calculates the number of business days:
// Calculate the number of business days between 2 date.
Local DateVar Start_Date := <INSERT YOUR START DATE FIELD HERE>;
Local DateVar End_Date := <INSERT YOUR END DATE FIELD HERE>;// Calculate the number of days.
Local NumberVar Business_Days := DateDiff("d",Start_Date,End_Date);// Number of days, minus the weekends (Saturdays and Sundays)
Business_Days := Business_Days - DateDiff("ww",Start_Date,End_Date,crSaturday) - DateDiff("ww",Start_Date,End_Date,crSunday);// Number of days, minus the holidays. Add the list of holidays in the array below.
Local DateVar Array Holidays :=
[ Date(2022,01,01), // New Year 2022
Date(2022,05,30), // Memorial Day
Date(2022,07,04), // Independance Day
Date(2022,09,05), // Labor Day
Date(2022,11,23)]; // Thanksgiving
Local NumberVar Nbr_Holidays := 0;
Local NumberVar x;
For x := 1 to Count(Holidays) Do
(
If (DayOfWeek(Holidays[x]) in 2 to 6) And (Holidays[x] in Start_Date to End_Date) Then
Nbr_Holidays := Nbr_Holidays + 1;
);Business_Days := Business_Days - Nbr_Holidays
- Note: It is possible to convert the above formula in a Custom Function, which can be re-use in other reports. For more information on Custom Function, see Crystal Reports Help.
- For a sample report providing an example on how to calculate business days, see the reports in the Attachments section below called:
- Calculate Business Days.rpt
- Calculate Business Days - Custom Function.rpt
Keywords
CR, Count of working days, count of days, count of two different parameters, Business days count , KBA , BI-RA-CR , Crystal Reports designer or Business View Manager , How To
Product
Attachments
Calculate Business Days.rpt |
Calculate Business Days - Custom Function.rpt |