I have a table for packages, where each package consists of Number of Days, Days included [any day(s) Sunday, Monday, ... ]
Package | Duration | Days Included
-------------------------------------------
Package 1 | 10 days | '1,2,3' [Sun, Mon, Tue]
Package 2 | 15 days | '4,5,6,7' [Wed, Thu, Fri, Sat]
Package 3 | 30 days | '1,2,3,4,5,6,7' [Sun, Mon, Tue, Wed, Thu, Fri, Sat]
etc
When customer selects any package (selecting the start date), I need to calculate the expiry date of that package based on the no. of days and days included in that package.
I need to create a function in which will return the Expiry Date providing the following 3 inputs.
- Start date
- Number of days
- Days to be included
Example:
For Package 1, starting from 13-Mar-2016, Correct End Date should be: 03-Apr-2016 (10 days would be 13,14,15,20,21,22,27,28,29 March, 03 Apr)
DECLARE @StartDate DATETIME
DECLARE @NoDays INT
DECLARE @EndDate DATETIME
SET @EndDate = DATEADD(DD, @NoDays, @StartDate)
So far I have done this, but it is including all 7 days.
Can anybody help how only the specific days can be included to get the correct expiry date?