title: The conversion of a varchar data type to a datetime data type resulted in an out-of-range value
body: <p>I have an error when I try to run my program:</p>
  
  <blockquote>
    <p>The conversion of a varchar data type to a  datetime data type
    resulted in an out-of-range value.</p>
  </blockquote>
  
  <p>Is there anything wrong with my select statement? </p>
  
  <pre><code>  int month=0;
  
      if (RadioButtonList1.SelectedIndex == 0)
      { month = 1; }
      else if(RadioButtonList1.SelectedIndex == 1)
      { month = 2; }
      else if(RadioButtonList1.SelectedIndex == 2)
      { month = 3; }
  
      SqlCommand cmd = new SqlCommand("SELECT thDate, thType, thAmountIn, thAmountOut from [Transaction] Where thDate &gt; dateadd(month, -" + month + ", GETDATE())", myConnection);
      da = new SqlDataAdapter(cmd);
      myConnection.Open();
      da.Fill(ds, "[Transaction]");
      myConnection.Close();
      if (!IsPostBack)
      {
          ViewState["vs_Transaction"] = (DataTable)ds.Tables["Transaction"];
          GridView1.DataSource = ds.Tables["Transaction"];
          GridView1.DataBind();
  </code></pre>
  
  <p>The below is my database table for thDate</p>
  
  <p><img src="https://i.stack.imgur.com/4Pd6F.png" alt="enter image description here"></p>
  
  <p><img src="https://i.stack.imgur.com/Vay4b.png" alt="enter image description here"></p>