如何根据当地时间进行搜索,占用时区

时间:2015-10-03 08:51:34

标签: search time

我有一系列营业时间的商店,想知道哪些商店目前正在营业。

问题在于商店遍布世界各地。

这就是查询查询的样子(例如我使用SQL,但没关系):

SELECT shops.name  FROM shops 
LEFT JOIN shops_openHours ON shops_openHours.shopId=shop.id 
WHERE shops_openHours.day=[day of week] 
AND shops_openHours.openTime < [now time] AND  shops_openHours.closeTime > [now time]

当我在当地时间存储工作时间时,由于时区而无法搜索。

当我以UTC存储工作时间时,由于夏令时,我无法搜索。

一些样本记录:

查询:

SELECT shops.name, shops_openHours.day day_of_week, 
shops_openHours.openTime, shops_openHours.closeTime FROM shops
LEFT JOIN shops_openHours ON shops_openHours.shopId=shop.id

结果:

name    day_of_week     openTime    closeTime   

shop1   'monday'        '09:00'     '18:00'
shop1   'tuesday'       '09:00'     '18:00'
shop2   'tuesday'       '10:00'     '19:00'
shop2   'tuesday'       '10:00'     '19:00'

示例查询(现在是星期一09:30):

SELECT shops.name  FROM shops LEFT JOIN shops_openHours ON shops_openHours.shopId=shop.id 
WHERE shops_openHours.day='monday' 
AND shops_openHours.openTime < '09:30' AND  shops_openHours.closeTime > '09:30'

结果:

name

shop1

0 个答案:

没有答案