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 !






Sql Function for Finding First Day of a Quarter


Posted Date: 24 Apr 2008    Resource Type: Code Snippets    Category: Date & Time

Posted By: @@@ Hyderabadi Biryani @@@       Member Level: Diamond
Rating:     Points: 3



The code sample is a sql function that takes a DATETIME variable as input and returns a DATETIME variable too. The output denots the first day of the quarter the given date belongs to.

For example first day of the 3nd quarter of 2008 is (i.e quarter starting july) tuesday.



CREATE FUNCTION [dbo].[fn_Get_First_Day_Of_Qtr] ( @pInputDate DATETIME )
RETURNS DATETIME
BEGIN

DECLARE @vOutputDate DATETIME

SET @vOutputDate = CAST(YEAR(@pInputDate) AS VARCHAR(4)) +
CASE WHEN MONTH(@pInputDate) IN ( 1, 2, 3) THEN '/01/01'
WHEN MONTH(@pInputDate) IN ( 4, 5, 6) THEN '/04/01'
WHEN MONTH(@pInputDate) IN ( 7, 8, 9) THEN '/07/01'
WHEN MONTH(@pInputDate) IN (10, 11, 12) THEN '/10/01'
END

RETURN @vOutputDate

END
GO





Responses


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

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
T-sql functions  .  T-sql function find first day of a quarter  .  Sql functions  .  Sql function to find first day of a quarter  .  First day of a quarter  .  

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: Last Day of the Month
Previous Resource: Get the System Date , using c#
Return to Discussion Resource Index
Post New Resource
Category: Date & Time


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

web conferencing

Contact Us    Privacy Policy    Terms Of Use