我有一个表,其中包含日期/时间值,它们分别分为日期和 int 字段,而不是单个日期时间。每行都有唯一的日期和小时组合,因此每天有 24 行。
当我需要在 where 语句中考虑这些时区调整时,我的挑战是选择与不同时区的用户相关的数据。例如,如果用户的时间比服务器时间早两个小时,那么 where 语句需要体现出来:
...where concat(theDate,' ',theHour) > convert_tz(concat('2012-01-01',' ','00:00:00'), '-8:00', '-6:00')
..例如,太平洋标准时间到中央时间。但显然我不能使用 convert_tz 或在 where 子句中计算它的值。
我想使用 convert_tz 而不是笨拙的 DATE_ADD 或其他什么。可以做什么?
也许我错了,您可以在 where 子句中使用 convert_tz。这里是核心问题:
select *, convert_tz(concat(theDay,' ',theHour), '-8:00', '-8:00') 'dayTZ'
from stats
where convert_tz(concat(theDay,' ',theHour), '-8:00', '-8:00') > '2011-01-25 05:00:00';
以上仍然返回早于 5 的小时值。