title: How to pass datetime from c# to sql correctly?
body: <p>I have a table and the date-times in it are in the format:</p>
  
  <pre><code>2011-07-01 15:17:33.357
  </code></pre>
  
  <p>I am taking a c# DateTime when I do a .ToString() on the object I am getting a DateTime in the format:</p>
  
  <pre><code>04/07/2011 06:06:17
  </code></pre>
  
  <p>I'm wondering how I correctly pass the correct DateTime through because when I run the SQL that is in our code it doesn't work (i.e. select the correct DateTime). I can't use SQL profiler.</p>
  
  <p>This is the code:</p>
  
  <pre><code>//looks to if a user has had any activity in within the last time specified
          public bool IsUserActivitySinceSuppliedTime(int userId, DateTime since)
          {
              //get everything since the datetime specified [usually 5 hours as this is 
              //how long the session lasts for
              string sql = "SELECT * FROM tbl_webLogging WHERE userid = @userid AND DateAdded &gt; @sinceDateTime";
  
              SqlParameter sinceDateTimeParam = new SqlParameter("@sinceDateTime", SqlDbType.DateTime);
              sinceDateTimeParam.Value = since;
  
              SqlCommand command = new SqlCommand(sql);
              command.Parameters.AddWithValue("@userid", userId);
              command.Parameters.Add(sinceDateTimeParam);
  
  
              using (SqlDataReader DataReader = GetDataReader(command))
              {
                  if (DataReader.HasRows)
                  {
                      return true;
                  }
                  else
                  {
                      return false;
                  }
              }
  
  
          }
  </code></pre>
  
  <p>UPDATE*******************</p>
  
  <p>I have run the following on the data:</p>
  
  <pre><code>SELECT * FROM tbl_webLogging 
  WHERE userid = 1 
  AND DateAdded &gt; '2011-07-01 07:19:58.000'
  </code></pre>
  
  <p>And</p>
  
  <pre><code>SELECT * FROM tbl_webLogging 
  WHERE userid = 1 
  AND DateAdded &gt; '04/07/2011 07:19:58'
  </code></pre>
  
  <p>One returns 53 records the other returns 69 records. How can this be? And when I pass the DateTime (04/07/2011 07:19:58) from c# to SQL no records show up at all!</p>