假设我在表格中有数据"事件"结构如下:
eventid | datetime_start | datetime_end | timezone
001 | 2016-01-01 10:00:00 | 2016-01-01 14:00:00 | America/Los_Angeles
002 | 2016-01-03 19:00:00 | 2016-01-03 22:00:00 | America/Los_Angeles
003 | 2016-01-17 02:00:00 | 2016-01-17 06:00:00 | America/New_York
004 | 2016-01-31 23:00:00 | 2016-02-01 01:00:00 | America/Los_Angeles
时区列允许日期/时间与输入完全一致,而不是标准化为UTC,GMT等。
我想查询表格以找到" now()"落在datetime_start和datetime_end之间:
SELECT eventid FROM events WHERE now() BETWEEN datetime_start AND datetime_end
然而,因为" now()"是基于一个固定的时区(在我的情况下是UTC),有没有办法转换" now()"在搜索时逐行匹配时区列?也许是以下精神的东西:
SELECT eventid FROM events WHERE CONVERT_TZ(now(),'UTC',timezone) BETWEEN datetime_start
AND datetime_end