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 get the first and last day of month


Posted Date: 14 May 2008    Resource Type: Code Snippets    Category: SQL
Author: Shivshanker CheralMember Level: Diamond    
Rating: Points: 10



--To get the first day of month and day name by any date
Declare @pInputDate Datetime
set @pInputDate=getdate()- 40
set @pInputDate= CAST(CAST(YEAR(@pInputDate) AS VARCHAR(4)) + '/' +
CAST(MONTH(@pInputDate) AS VARCHAR(2)) + '/01' AS DATETIME)
--Will give First date of the month

--Will give day of the date
select @pInputDate AS First_Day_of_mth, datename(dw,@pInputDate) AS Day_Name

-- to Get last date of a month
Declare @Enddate Datetime
set @Enddate = getdate()
SELECT DATEADD(s,-1,DATEADD(mm, DATEDIFF(m,0,@Enddate)+1,0)) as lastday


how to write a query for getting the first day of the month?
exeample : oct - 1 - 2007 means monday i want to get like this.

SELECT MONTH(getdate()) as month1, DAY(0) as date, YEAR(getdate()) as year1




Responses


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

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

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: Advantages of UDFs
Previous Resource: SQL Date Time important functions
Return to Discussion Resource Index
Post New Resource
Category: SQL


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use