Search code examples
sql-server-2008dateadddatepart

DATEADD, DATEPART not returning desired results


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.


Solution

  • 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) ))