title: Comparing two dates with sql/rails
body: <p>I am quite confused about comparing these dates. I have a line of code which is:</p>
  
  <p><code>.where('invoices.invoice_status &gt;= 100 AND invoices.shipping_mode = -1 AND invoices.archived_at IS NULL AND invoices.written_off_at IS NULL AND invoices.signup IS FALSE AND invoices.send_at &gt;= ?', since_time)</code></p>
  
  <p>send_at is <code>Thu, 12 Jul 2018 17:18:53 CEST +02:00</code></p>
  
  <p>since_time is <code>2018-07-12T17:12:37.673+02:00</code></p>
  
  <p>I believe my code is faulty and won't work because these datetimes look different. Am I correct?</p>
  
  <p>UPDATE</p>
  
  <pre><code>Hubspot::Setting Load (0.8ms)  SELECT  "hubspot_settings".* FROM "hubspot_settings" WHERE "hubspot_settings"."company_id" = $1 LIMIT 1  [["company_id", 10]]
  19:09:04 log.1       |    (0.7ms)  SELECT COUNT(*) FROM "data_privacy_downloads" WHERE "data_privacy_downloads"."company_id" = $1  [["company_id", 10]]
  19:09:04 log.1       |   User Load (0.5ms)  SELECT "users".* FROM "users" INNER JOIN "user_company_links" ON "users"."id" = "user_company_links"."user_id" WHERE "user_company_links"."company_id" = $1  [["company_id", 10]]
  19:09:04 log.1       |    (0.6ms)  SELECT SUM("invoices"."actual_total") FROM "invoices" WHERE "invoices"."company_id" = $1 AND (invoice_status &gt;= 100 AND archived_at IS NULL and is_duplicate IS NOT TRUE) AND ("invoices"."invoice_date" BETWEEN '2018-01-01' AND '2018-07-31') AND ("invoices"."invoice_date" BETWEEN '2018-02-01' AND '2018-02-28')  [["company_id", 10]]
  19:09:04 log.1       |    (0.6ms)  SELECT SUM("invoices"."actual_total") FROM "invoices" WHERE "invoices"."company_id" = $1 AND (invoice_status &gt;= 100 AND archived_at IS NULL and is_duplicate IS NOT TRUE) AND ("invoices"."invoice_date" BETWEEN '2018-01-01' AND '2018-07-31') AND ("invoices"."invoice_date" BETWEEN '2018-03-01' AND '2018-03-31')  [["company_id", 10]]
  19:09:04 log.1       |    (0.6ms)  SELECT SUM("invoices"."actual_total") FROM "invoices" WHERE "invoices"."company_id" = $1 AND (invoice_status &gt;= 100 AND archived_at IS NULL and is_duplicate IS NOT TRUE) AND ("invoices"."invoice_date" BETWEEN '2018-01-01' AND '2018-07-31') AND ("invoices"."invoice_date" BETWEEN '2018-04-01' AND '2018-04-30')  [["company_id", 10]]
  19:09:04 log.1       |    (0.6ms)  SELECT SUM("invoices"."actual_total") FROM "invoices" WHERE "invoices"."company_id" = $1 AND (invoice_status &gt;= 100 AND archived_at IS NULL and is_duplicate IS NOT TRUE) AND ("invoices"."invoice_date" BETWEEN '2018-01-01' AND '2018-07-31') AND ("invoices"."invoice_date" BETWEEN '2018-05-01' AND '2018-05-31')  [["company_id", 10]]
  19:09:04 log.1       |    (1.8ms)  SELECT SUM("invoices"."actual_total") FROM "invoices" WHERE "invoices"."company_id" = $1 AND (invoice_status &gt;= 100 AND archived_at IS NULL and is_duplicate IS NOT TRUE) AND ("invoices"."invoice_date" BETWEEN '2018-01-01' AND '2018-07-31') AND ("invoices"."invoice_date" BETWEEN '2018-06-01' AND '2018-06-30')  [["company_id", 10]]
  19:09:04 log.1       |    (0.4ms)  SELECT SUM("invoices"."actual_total") FROM "invoices" WHERE "invoices"."company_id" = $1 AND (invoice_status &gt;= 100 AND archived_at IS NULL and is_duplicate IS NOT TRUE) AND ("invoices"."invoice_date" BETWEEN '2018-01-01' AND '2018-07-31') AND ("invoices"."invoice_date" BETWEEN '2018-07-01' AND '2018-07-31')  [["company_id", 10]]
  19:09:04 log.1       |   EmailSubscription Load (0.6ms)  SELECT "email_subscriptions".* FROM "email_subscriptions" WHERE "email_subscriptions"."company_id" = $1  ORDER BY email_subscriptions.email_type asc, lower(email_subscriptions.email) asc  [["company_id", 10]]
  19:09:04 log.1       |    (0.7ms)  SELECT COUNT(*) FROM "invoices" WHERE "invoices"."company_id" = $1 AND (invoices.archived_at IS NULL AND invoices.signup IS FALSE AND invoices.send_at IS NOT NULL AND invoices.written_off_at IS NULL AND invoices.send_at &gt;= DATE('2018-07-27') AND DATE(invoices.send_at) &lt;= '2018-07-31 21:59:59.999999')  [["company_id", 10]]
  </code></pre>