I need to subtract a number of business days (1-15 days) from a specific date, for example subtracting 5 business days from 2013-12-27
should return 2013-12-20
, is there an easy way to do that?
To calculate workdays in Excel, follow these simple rules: To add workdays, enter a positive number as the days argument of a WORKDAY formula. To subtract workdays, use a negative number in the days argument.
The NETWORKDAYS Function[1] calculates the number of workdays between two dates in Excel. When using the function, the number of weekends are automatically excluded. It also allows you to skip specified holidays and only count business days. It is categorized in Excel as a Date/Time Function.
You can use the EDATE function to quickly add or subtract months from a date. The EDATE function requires two arguments: the start date and the number of months that you want to add or subtract. To subtract months, enter a negative number as the second argument. For example, =EDATE("9/15/19",-5) returns 4/15/19.
If you'd like to calculate the difference between two dates while excluding weekends and holidays, use the NETWORKDAYS function instead. This also looks for 3 arguments: the start date, the end date, and optional holidays. Unlike the WORKDAY function, the NETWORKDAYS function does include or count the start day.
One way to do that is to pre-create a table with all the dates for couple of years in advance and select from that table. This way you can mark saturdays, sundays, holidays, etc.
This post explains how to do it using a recursive CTE:
Business Days Calc Using Recursive CTE
DECLARE @StartDate DATETIME
DECLARE @EndDate DATETIME
SET @StartDate = '2013/10/01'
SET @EndDate = '2013/10/31'
SELECT
(DATEDIFF(dd, @StartDate, @EndDate) + 1)
-(DATEDIFF(wk, @StartDate, @EndDate) * 2)
-(CASE WHEN DATEPART(dw, @StartDate) = 1 THEN 1 ELSE 0 END)
-(CASE WHEN DATEPART(dw, @EndDate) = 7 THEN 1 ELSE 0 END)
AS [TotalWorkingDays]
Result
TotalWorkingDays
23
Important Note
This method will only ignore Saturdays and Sundays, If you want to exclude National Holidays and other seasonal Holidays you will need to make use of a calender table as Zdravko Danev has already mentioned.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With