First day of next year for SQL Server?
It doesn't have to be that hard. I just need the following:
SET @DueDate = CONVERT (DATETIME, '01/01/2010')
However, I need it pragmatically, so if it were in March 2010, the date would be "01/01/2011".
I know it's easy, but my brain doesn't fit. I'm pretty sure this is with DateAdd and getdate()
.
source to share
The number of year boundaries between zeros and years is less than one (Dec 31, 1899), add back.
SELECT DATEADD(year, DATEDIFF(year, -1, GETDATE()), 0)
Try next year's date to get 2011. Because January 1, 2010 is the beginning of next year in 2009 ...
SELECT DATEADD(year, DATEDIFF(year, -1, '2010-03-21'), 0)
source to share
Based on Database Journal article: How to Calculate Different SQL Server Dates :
First day of next year
I am using a year interval (yy) to display the first day of the next year.
select DATEADD (yy, DATEDIFF (yy, -1, getdate ()), 0)
source to share
Using some parts of the examples above, you can do this as well. This now assumes that your acceptable date format is Md-yyyy.
DATEADD(year, 1,'1-1-'+convert(varchar,DATEPART(YYYY,GetDate())))
Note. You get the current date, get the year part, create a string that converts to a date, and then add it to the year.
source to share