Hello, I need to get the difference between two dates using the select DATEDIFF(year, 1997-01-01, getdate()) function select DATEDIFF(year, 1997-01-01, getdate()) but the function returns an select DATEDIFF(year, 1997-01-01, getdate()) value, the function that calculates the year from the date (i.e. the 2nd argument ), if we execute the year function (1997-01-01) then it will return 1905, in my table there is a DateOfBurn field and its date (when I fill in, I just enter "1990-02-02") and there is a calculated column Age DATEDIFF(year, DateOfBurn, getdate()) Help please make the request correctly.

  • one
    And you did not try to conclude the date '1997-01-01' in quotes (single). But since 1997-01-01 = 1995 and how it will be converted to the date of the mind I will not attach - Mike
  • Specify the type of DBMS please. In different subd differently. In MSSQL, it’s generally just select year(getdate()) - nick_n_a
  • @nick_n_a He has MS SQL. Just checked, on MySQL year (1997-01-01) (the date without quotes) gives NULL, and on MS SQL it is just 1905, see the number 1995 so it converts to the date :) - Mike
  • one
    This is converted as 1995 days from the date '1900-01-01' - the date is '1905-03-21' in 1905. - i-one
  • 2
    select year ('1997-01-01') = 1997 (MS SQL) - Ruslan_K

1 answer 1

you need to pass the date as a string in quotes

 DATEDIFF(year, '1997-01-01', getdate())