title: Convert string to datetime to year and month SQL
body: <p>How do i get the year(2009) and month(12) from the string datetime, following give me correct full date but wrong year (1905-07-03 00:00:00.000) and month (1900-01-13 00:00:00.000). I have tried changing YYYY to year and MM to month.</p>
  
  <pre><code>Declare @date dateTime;
  Declare @CurrentYear datetime;
  Declare @CurrentMonth datetime;
  Select @date = CONVERT ( datetime , '20091231' ,112 );
  Select @CurrentYear = DATEPART(YYYY,@date);
  --Select @CurrentYear = YEAR(@Date);  &lt;---- still wrong year
  Select @CurrentMONTH = DATEPART(MM,@date);
  --Select @CurrentMonth = MONTH(@date);   &lt;---- still wrong year
  select @date as fulldate, @CurrentYear as [year], @CurrentMonth as [Month];
  </code></pre>
  
  <p>None of the SO suggestions has worked so far.</p>
  
  <p>regards
  K</p>