Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

t-sql first last day date of the month

By Bernabe Diaz,

If you need calculate the fisrt or the last day date of a given date this stored procedure can help you

Description: returns the first or last day date
of the month
@d // the date ; if null is the current date
@FL first or last date day of the month
for 1 is the first day otherwise the last

testing:

DECLARE @R AS DATETIME
EXECUTE dbo.Usp_FirstLastMonthDayDate @R=@R,@FL=2, @D='20000223'

returns:

2000-02-29 00:00:00.000

 

-- with default values

DECLARE @R AS DATETIME
EXECUTE dbo.Usp_FirstLastMonthDayDate @R=@R

returns:

2009-11-01 23:10:37.393

 

Total article views: 2721 | Views in the last 30 days: 9
 
Related Articles
FORUM

Problem with SET of return Params

the first "SET @return_value = '-1'" will work but after that @return_value is never set

BLOG

SQLBIGeek's Function Friday - Return First Day of Quarter

Brian K. McDonald SQLBIGeek Twitter: @briankmcdonald Welcome to the first of my “SQLBIGee...

ARTICLE

Returning a Subset of a Recordset

Stateless programming can be tricky... In case you ever need to return a specified subset of a query...

BLOG

Returning Stuff to Amazon

I've used Amazon for years for the sheer convenience, and recently was the first time I ever needed ...

FORUM

first element in sublist

first element in sublist

Tags
date manipulation    
t-sql    
 
Contribute

Join the most active online SQL Server Community

SQL knowledge, delivered daily, free:

Email address:  

You make SSC a better place

As a member of SQLServerCentral, you get free access to loads of fresh content: thousands of articles and SQL scripts, a library of free eBooks, a weekly database news roundup, a great Q & A platform… And it’s our huge, buzzing community of SQL Server Professionals that makes it such a success.

Join us!

Steve Jones
Editor, SQLServerCentral.com

Already a member? Jump in:

Email address:   Password:   Remember me: Forgotten your password?
Steve Jones