This project is archived and is in readonly mode.

#2925 ✓duplicate
Ari Epstein

DateTime:to_s(:db) does not convert to UTC

Reported by Ari Epstein | July 20th, 2009 @ 05:31 PM | in 2.x

ActiveRecord saves datetime fields in UTC, but in prepared statements (for select queries), the quote method does not perform the same conversion. So, for example:

(using US Eastern Time) Shift.create(:starts_at => DateTime.now - 100.minutes, :ends_at => DateTime.now - 50.minutes)
Shift.find(:conditions => ['ends_at < ?',DateTime.now])
=> [] Shift.find(:conditions => ['ends_at < ?',DateTime.now.utc])
=> Shift(Shift id: 1, starts_at: ...)

This doesn't seem the right behavior to me. Shouldn't quote automatically convert to UTC since that's the zone in which the database stores times? Could be done in the to_s(:db) formatter perhaps?

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Pages