Get First/Last Date of Month

October 12, 2009



>>Script Language and Platform: TSQL/SQL Server 2000
This script returns the first/last date of the month after receiving any date of the month.

Author: Anjum Niaz


SET QUOTED_IDENTIFIER ON 
GO
SET ANSI_NULLS ON 
GO

CREATE FUNCTION [GetFirstDateofMonth] 
(@Date as DateTime)  

RETURNS DateTime AS  
BEGIN 

Declare @FirstDate DateTime 
Set @FirstDate = DateAdd(Day, 1, @Date - Day(@Date) + 1) -1

RETURN @FirstDate

END

GO

CREATE  FUNCTION [GetLastDateofMonth] 
(@Date as DateTime)  

RETURNS DateTime AS  
BEGIN 

Declare @LastDate DateTime 
Set @LastDate = DateAdd(Month, 1, @Date - Day(@Date) + 1) -1

RETURN @LastDate

END
GO 

Disclaimer: We hope that the information on these script pages is valuable to you. Your use of the information contained in these pages, however, is at your sole risk. All information on these pages is provided "as -is", without any warranty, whether express or implied, of its accuracy, completeness, or fitness for a particular purpose... Disclaimer Continued


Back to Database Journal Home








The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers