title: SQLite /Rails datetime query problems
body: <p>I'm building a Rails application, which is creating orders from a schedule.  The schedule has a time in format hh:mm, and ticks for each day of the week.  A method occasionally checks the schedules, and creates any orders required by the schedule.</p>
  
  <p>Firstly, I build up the time for this week's order in a Ruby DateTime object, then check if it exists, and create if not e.g.:</p>
  
  <pre><code>order = Order.where( :delivery_datetime = del_datetime )
  unless order.any?
    Order.create( :status =&gt; 'Estimated', :delivery_datetime =&gt; del_datetime )
  end
  </code></pre>
  
  <p>That works as expected on my machine, but when other people picked it up from the repository, it would recreate the orders every time.  I investigated the SQL it was using, and the problem seemed to be it was creating a where clause slightly different to the insert statement:</p>
  
  <pre><code>SELECT COUNT(*) FROM orders WHERE delivery_datetime = '2011-06-30 18:00:00.000000'
  INSERT INTO orders (delivery_datetime) VALUES ('2011-06-30 18:00:00.000000000')
  </code></pre>
  
  <p>So the difference is the three extra zeroes in the partial second field.  I understand SQLite doesn't have real date types, so these are different just because the strings are different.  The problem I am having now is that I can't seem to force the format of the inserted string.  E.g. even if I do the following:</p>
  
  <pre><code>Order.create( :status =&gt; 'Estimated',
                 :delivery_datetime =&gt; del_datetime.strftime( '%Y-%m-%d %H:%M' ) )
  </code></pre>
  
  <p>the insert statement still uses a 'standard' format - but with 6 zeroes on my instance, and 9 on another.</p>