title: How to validate valid datetime in c# before submitting to server
body: <p>Hi I am getting this error:</p>
  
  <p>Writing record number: </p>
  
  <blockquote>
    <p>60479System.Data.SqlTypes.SqlTypeException: SqlDateTime overflow. Must
    be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM.</p>
  </blockquote>
  
  <p>I have tried this :</p>
  
  <pre><code>try
  {
       DateTime dt = Convert.ToDateTime(fireBirdReader["DUEDATE"]);
       cmd.Parameters.AddWithValue("@DUEDATE", fireBirdReader["DUEDATE"]);
  }
  catch
  {
       cmd.Parameters.AddWithValue("@DUEDATE", DateTime.Now);
  }
  </code></pre>
  
  <p>Also I have tries this:</p>
  
  <pre><code>DateTime temp;
  if(DateTime.TryParse(startDateTextBox.Text, out temp))
  {
  cmd.Parameters.AddWithValue("@DUEDATE", temp);
  }
  else
  {
  cmd.Parameters.AddWithValue("@DUEDATE", DateTime.Now);
  }
  </code></pre>
  
  <p>But none of them working. I am using c# and console application.</p>
  
  <p>Why you are marking as duplicate that answer is not working in my case. Can you please test it yourself. Do not try to over smart before try. I can also search google and stackoverflow.</p>