title: DATEDIFF function in the boundary conditions problem
body: <p>Could anyone help me understand the following, the result of date difference in year is 0,
  but I think result should be 1 based on the condition, since the DATEADD function would return 2015-12-31, and it is greater than @ToDate 2015-01-01.
  here is the link for the article, the first example
  <a href="https://sqlhints.com/2015/07/10/how-to-get-difference-between-two-dates-in-years-months-and-days-in-sql-server/" rel="nofollow noreferrer">https://sqlhints.com/2015/07/10/how-to-get-difference-between-two-dates-in-years-months-and-days-in-sql-server/</a></p>
  <pre class="lang-sql prettyprint-override"><code>DECLARE @FromDate DATETIME = '2014-12-31', 
          @ToDate DATETIME = '2015-01-01'
  SELECT @FromDate 'From Date', @ToDate 'To Date',
   DATEDIFF(YEAR, @FromDate, @ToDate)
     -
   (CASE
     WHEN DATEADD(YEAR, 
             DATEDIFF(YEAR, @FromDate,@ToDate), @FromDate)
         &gt; @ToDate THEN 1 
           ELSE 0 END) 'Date difference in Years'
  </code></pre>
  <p>RESULT:
  <a href="https://i.stack.imgur.com/VNZjh.png" rel="nofollow noreferrer">enter image description here</a></p>