DATEADD, DATEPART not returning desired results
-
02-06-2021 - |
Domanda
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.
Soluzione
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) ))
Altri suggerimenti
Can you try this?
select DATEPART(YYYY,(DATEADD(YEAR, 1,current_timestamp)))
--It will give result 2016
select DATEADD(YEAR, 1, current_timestamp)
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
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow