title: Compare two Datetimes one from Datetimepicker and one from MySql Database
body: <p>I have a strange problem...I have a MySql db with some columns and one of the column is date_purchased which is of type date_time. </p>
  
  <p>I am using C# and made a DatetimePicker and user selects a date.</p>
  
  <pre><code>private void dateTimePicker1_ValueChanged(object sender, EventArgs e)
      {
  
          varDate = dateTimePicker1.Value;
  
      }
  </code></pre>
  
  <p>Now the problem is I have to compare the two datetimes (one from the database and one from the User) and I should display the records that are less than the date selected by the user(varDate).</p>
  
  <pre><code>select * from orders where date_purchased &lt; = '" + varDate + "'";
  </code></pre>
  
  <p>I am executing this query but i am getting an exception</p>
  
  <pre><code>You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= '12/25/2011 8:01:31 PM'' at line 1
  </code></pre>
  
  <p>I wrote the connection string and all and I am struck at the query.
  Any Help will be much appreciated...
  Thanks,
  Subash</p>