开发者

date range in timezone

application.rb

config.time_zone = 'Athens'

I want to list entries which are published between any date ranges.The query below starts listing entries which are published_at after 03:00 not 00:00 Any help will be appreciated.

@from_date = (Time.zone.now-1.day).to_date.to_datetime #i开发者_运维技巧am trying to set time to 00:00
@to_date = (Time.zone.now+1.day).to_date.to_datetime
Entry.where(:spam => false, :published_at => @report_from_date..@report_to_date)


You might look at using beginning_of_day and end_of_day. For example, to show everything within the current day:

@from_date = Time.zone.now.beginning_of_day # Returns 2011-08-08 00:00:00
@to_date = Time.zone.now.end_of_day # Returns 2011-08-08 23:59:59
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜