Technical Article

ChangeDateTpFirstOfNextMonth

,

See script for further instructions. You can use it as a simple select statement, put it in code, or any other way you see fit. This script is about as basic as it comes.

The getdate() function in the script is only used for example purposes only. Use what ever date you feel like or adjust to use a different input parameter.

/*
Name: ChangeDateToFirstOfNextMonth
Author: Kristina de Don
Purpose: Takes a parameter @NextMonth datetime and changes it to be
the first of the month for the following month.
*/
--example of how it works with getdate() function. 
--The "-" is the part that allows you to go back to the begining of the month

SELECT dateadd(m,1, DATEADD(day, -(datediff(d, 1,datepart(d, getdate()))), getdate()) )

--with input parameter
declare @NextMonth datetime

set @NextMonth = getdate() -- put the date you need converting here
SELECT dateadd(m,1, DATEADD(day, -(datediff(d, 1,datepart(d, @NextMonth))), @NextMonth) )

Rate

2.33 (6)

You rated this post out of 5. Change rating

Share

Share

Rate

2.33 (6)

You rated this post out of 5. Change rating