我有游戏表,我想从中获取在 11:00:00 到 14:00:00 之间开始的游戏。但我存储在数据库中的 start_in_time 是 UTC。我想获取游戏开始时间 11:00:00 EST 和 14:00:00 EST。
Game.where("Time((start_in_time at time zone 'UTC') at time zone 'EST') between '11:00:00' and '14:00:00' ")
我已使用 mysql 作为查询上方的数据库,但在数据库中我收到语法错误。如何使其正确?
最佳答案
获取用户时区,
@game.timezone = 'EST'
Game.where('start_in_time > ? AND start_in_time < ?',((DateTime.parse("11am").to_time.in_time_zone('EST')).time.strftime("%I:%M %p")),(DateTime.parse("2pm").to_time.in_time_zone('EST')).time.strftime("%I:%M %p"))
这是一个示例查询,
Game.where('start_in_time > ? AND start_in_time < ?',((DateTime.parse("11am").to_time.in_time_zone('EST')).time.strftime("%I:%M %p")),(DateTime.parse("2am").to_time.in_time_zone('EST')).time.strftime("%I:%M %p"))
Game Load (0.6ms) SELECT `games`.* FROM `games` WHERE (start_in_time > '06:30 AM' AND start_in_time < '09:30 PM')
关于mysql - 获取带有 EST 时区时间的游戏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40188408/