title: What is happening in this query?
body: <p>I am trying to get the last of month, and in order to that i have written the following, to calculate the no. of days between today and the last date.</p>
  
  <pre><code>    select datediff(DAY,GETDATE(),dateadd(m,1,getdate()))-GETDATE()
  </code></pre>
  
  <p>the <strong>bold</strong> part gives me the no. of days between today and a month from today, say 30 or 31. and then I am subtracting today's date from 30 or 31, which is " -getdate() "</p>
  
  <p>The output for the above query is </p>
  
  <p><strong>1786-06-06 11:44:30.540</strong></p>
  
  <p>Could you please explain what is happening in the query? I am not looking for a solution, I would like to know how is SQL-Server interpreting the query.</p>
  
  <p>Thanks. :)</p>