Reputation: 55
I am not sure if my brain is working because it is Monday. I want to add a single year to the current year but I am getting undesired results.
Here is what I am getting:
select current_timestamp
Output:2012-04-23 09:57:45.777
select DATEADD(YEAR, 1, DATEPART(YEAR,current_timestamp))
Output: 1906-07-06 00:00:00.000
select DATEPART(year,current_timestamp)
Output: 2012
Something as simple as this and for some reason I am failing to catch the issue.
Upvotes: 1
Views: 3519
Reputation: 1
SELECT cast(DATEPART(YEAR,current_timestamp) as datetime);
go return 1905-07-10 00:00:00.000 that's the problem
select dateadd(year,1, current_timestamp);
go return 2017-07-25 23:13:49.700
Upvotes: -1
Reputation: 11
Can you try this?
select DATEPART(YYYY,(DATEADD(YEAR, 1,current_timestamp)))
--It will give result 2016
Upvotes: 1
Reputation: 300519
select DATEADD(YEAR, 1, current_timestamp)
if you only want the date part:
select DATEADD(d, 0, DATEDIFF(d, 0, DATEADD(YEAR, 1, current_timestamp) ))
Upvotes: 1