all my date ties are stored with the standard :db format and being in
western Europe, I have an UTC offset +1
Time.now.at_beginning_of_day
=> 2012-02-07 00:00:00 +0100

I'ld like to know if I am right ( or wrong) in my date time based
queries like :

scope :today, lambda {
where("created_at >= ? AND created_at < ? ",
Time.now.at_beginning_of_day, Time.now.tomorrow.at_beginning_of_day)
}

which generates:
SELECT `event_logs`.* FROM `event_logs` WHERE (created_at >=
'2012-02-06 23:00:00' AND < '2012-02-07 23:00:00' )

--------------
OR should I use the Time.now.utc to cope with the :db format ?

scope :today, lambda {
where("created_at >= ? AND created_at < ? ",
Time.now.utc.at_beginning_of_day,
Time.now.utc.tomorrow.at_beginning_of_day)
}
which generates:
SELECT `event_logs`.* FROM `event_logs` WHERE (created_at >=
'2012-02-07 00:00:00' AND created_at < '2012-02-08 00:00:00' )

my guess is the 2nd scope , but I am not sure

thanks for your feedback

--
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 rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

Discussion Posts

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 1 of 7 | next ›
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedFeb 7, '12 at 5:13p
activeFeb 8, '12 at 1:17p
posts7
users4
websiterubyonrails.org
irc#RubyOnRails

People

Translate

site design / logo © 2022 Grokbase