title: TSQL need to return last day of month only, how do I drop year, month & time?
body: <p>I am writing a function in T-SQL returning the last day of the month regardless of the date input.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>Alter Function dbo.FN_Get_Last_Day_in_Month2
  (@FN_InputDt    Datetime)
  Returns smalldatetime
  as 
  Begin
  
  Declare @Result  smalldatetime
  Set    @Result =
  
         case when @FN_InputDt &lt;&gt; 01-01-1900 then 
         DATEADD(m, DATEDIFF(M, 0,@FN_InputDt)+1, -1)
         Else 0 End
  
  Return @Result
  
  End 
  </code></pre>
  
  <p>The code is not working correctly, here is a test that shows the bad behavior:</p>
  
  <pre><code>SELECT dbo.fn_get_last_day_in_month (07-05-2010)
  </code></pre>
  
  <p>Here is the (incorrect) result:</p>
  
  <pre><code>2010-07-31 00:00:00
  </code></pre>