Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
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: 2788 | 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

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

SQLBIGeek's Function Friday - Return First Day of Quarter

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

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