title: What is the best practice to query dates in SQL when parameterised queries are not possible
body: <p>My brief is to implement a interface which has a method that looks something like 'GetValuesSqlStatement' below:</p>
  
  <pre><code>public string SqlPattern { get { ... } }
  //this varies; eg. "SELECT name FROM someTable WHERE startDate &lt; {0}"
  
  public string DatabaseType { get { ... } }
  //this varies; eg. "SqlServer"
  
  public string GetValuesSqlStatement(List&lt;object&gt; paramValues)
  {
      //...desired logic here, using DatabaseType, SqlPattern and paramValues
  }
  </code></pre>
  
  <p>Now, because this must produce an executable SQL statement, I can't use parameters in the execution of the query. And the interface I must implement is non-negotiable. What is the best way to proceed to make sure the dates in the result are interpreted by the database query engine correctly? Assuming that the paramValues contain .NET DateTime objects, how should these be formatted to string before plugging into the SQL pattern string? What is the most common universal date format across must databases? (eg. something like 'dd-mmm-yyyy'). </p>
  
  <p>NB: I only really need to worry about Sql Server from 2005 onwards and Oracle 10g onwards. So the SQL must be valid T SQL and PL SQL and mean the same thing in both flavours.</p>