title: How to get number of days from month and year
body: <p>I want to get the number of days in the month which the user specifies. I am using this it works for most months except for Feb and leap year. It shows 28 days and not 29. Can you solve this?</p>
  
  <pre><code>begin
  declare @year int
  declare @month int
  select @year = 2012
  select @month = DATEPART(mm,CAST('August'+ ' 2012' AS DATETIME))
  select  datediff(day, 
          dateadd(day, 0, dateadd(month, ((@year - 2012) * 12) + @month - 1, 0)),
          dateadd(day, 0, dateadd(month, ((@year - 2012) * 12) + @month, 0))) as number_of_days
  
  end
  </code></pre>
  
  <p>Or If not can you tell me another approach to do this. It should use <code>@year</code> and <code>@month</code> and the code to find the days can be any!</p>