On 12 April 2012 09:36, Damjan Rems <[email protected]> wrote: > Rails 2.3.2, Ruby 1.9.3 > > I want to get all records for one month from charges table. > > recs = Charge.where(["date >= ? and date < ?", t.beginning_of_month, > t.next_month.beginning_of_month]) > > and this transforms into this query on PostgreSQL > > SELECT "charges".* FROM "charges" WHERE (date >= '2012-03-31 > 22:00:00.000000' and date < '2012-04-30 22:00:00.000000') > > Which is wrong. Dates should have been 2012-04-01 00:00:00.000000 and > 2012-05-01 00:00:00.000000 > > What is wrong?
Nothing is wrong. Those dates are the beginning of the month for the timezone that t is in, converted to UTC as times in the database are in UTC. In order to get the result you expect then make sure that t is a UTC time not a local time. Colin -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

