C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




To Calculate 30 Working days from the Input Date


Posted Date: 03 Oct 2008    Resource Type: Code Snippets    Category: SQL

Posted By: Vignesh       Member Level: Silver
Rating:     Points: 5



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




Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Stored procedure  .  Sql  .  Date  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Exception handing (TRY/CATCH) in SQL SERVER 2005
Previous Resource: How to get the columns in tha table?
Return to Discussion Resource Index
Post New Resource
Category: SQL


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

online optimum rewards

Contact Us    Privacy Policy    Terms Of Use