This code shows how to calculate 30 working days from the input date
/*To calculate 30 working days from today*/
/*Declerations*/ DECLARE @InputDate DATETIME DECLARE @I INT DECLARE @NoOfDays INT DECLARE @CurrDay INT DECLARE @ResultDate DATETIME DECLARE @Cntr INT DECLARE @DummyVal INT
SET @InputDate = '09/01/2008' -- i/p date SET @DummyVal = 0 SET @Cntr = 0 SET @NoOfDays = 30
SET @CurrDay = DATEPART(dw, @InputDate) --curr day
SET @DummyVal = 6-@CurrDay --working days at the end of the week (friday) SET @Cntr = @Cntr + @DummyVal
SET @ResultDate = DATEADD(DD,@DummyVal,@InputDate) --date at the end of the week (friday)
SET @I = 1
WHILE (@I <= 7) BEGIN
SET @ResultDate = DATEADD(DD,1,@ResultDate)
IF(@I <> 1 AND @I <> 7) --if not saturday and sunday BEGIN SET @Cntr = @Cntr + 1 END
IF(@Cntr = @NoOfDays) GOTO LBL
IF(@I = 7) SET @I = 0
SET @I = @I + 1 END
LBL:
SET @ResultDate = DATEADD(DD,1,@ResultDate)
PRINT '@ResultDate:' PRINT @ResultDate
|
No responses found. Be the first to respond and make money from revenue sharing program.
|