Query in rails with specific time zone -
i trying make query timezone set in application query grouping default utc time zone. how can use time zone set in config file?
i have following code:
trans = table.order("date(created_at)").group("date(created_at)").limit(30) trans.count.each |key,value| labels_array.push key sales_array.push value end trans.sum(:amount).each |key,value| revenue_array.push value end
i think set
# application.rb config.time_zone = 'your timezone'
that's change rails timezone not activerecard (continue save in utc). if want change activerecord timezone
# application.rb config.time_zone = 'your timezone' config.active_record.default_timezone = :local
my opinion - it's not bad think it's practice when system in utc (database, cache, etc.).
you can group timezone using sql
#mysql example .group("date(convert_tz(your_field, 'utc','<name of time zone>'))")
Comments
Post a Comment