开发者

Rails get Date part of DateTime with Time Zone

I'm trying to execute a query in rails 3 with the following syntax: CourseOrder.where("DATE(ordered_at) = ?", date).

My problem is that r开发者_StackOverflowails saves all times in UTC, so in my Timezone (+2) at 0:33 its the 4th but in UTC its the 3th of the month. Is there a way to query the date part of a DateTime with Timezone?


Don't use date, do it like this instead:

time = DateTime.civil_from_format(:local, 2011, 4, 9)
CourseOrder.where("ordered_at > ? AND ordered_at < ?", time - 1.day, time)

You're storing a datetime, so query that instead of trying to use date, which doesn't account for Timezones.


solved the problem with a change in which values I compare.

I have a Date value to, and now I'm comparing a date value with a date value which is better than comparing date value with datetime value which have to fail. thanks for leading me to the right direction

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜