On Tue, Feb 7, 2012 at 6:12 PM, Erwin <yves_duf...@mac.com> wrote: > 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 >
Just curious, could you not juet use Date (instead of Time). E.g. for contract start and end dates and programming that for an international company in a previous life, I had changed back certain fields from the initial choice of "time" (as seemed obvious because of the default for "created_at" etc.) to "date" (Contract#starts_date and Contract#end_date). So, it was then trivial to compare, understand and display the date to the users. For the abstract concept of a "date", I learned the hard way to use a Date (and not Time). So, maybe your database could have a column "creation_date" that is really a Date and that is initialized when the record is created in the local time zone of the user for which the Date has a "real-life" sense. And then the start_date or creation_date of e.g. his/her membership has an obvious local meaning. Just my 2 cents (and venting some old frustrations I suffered over this ...) HTH, Peter -- 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+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.