For at finde ud af shop_id'er, er det åbent for NOW()
SELECT *
FROM `shop_hours`
WHERE `day_of_week` = DATE_FORMAT(NOW(), '%w')
AND CURTIME() BETWEEN `open_time` AND `close_time`
Forældet :
For at finde i morgen 's tilgængelig open_time
s:
SELECT *
FROM `shop_hours`
WHERE `day_of_week` = DATE_FORMAT(DATE_ADD(NOW(), INTERVAL 1 DAY), '%w')
Rediger 2:
For at finde den næste tilgængelige open_time
s:
SELECT `shop_id`,
MIN(CAST(CONCAT(DATE(DATE_ADD(NOW(), INTERVAL ((7 + DATE_FORMAT(NOW(), '%w') - `day_of_week`) % 7) DAY)), ' ', `open_time`) AS DATETIME)) AS `next_open_datetime`
FROM `shop_hours`
GROUP BY `shop_id`
Rediger :
DATE_FORMAT(*DATE*, '%w')
bruger formatet 0 = Sunday ... 6 = Saturday
Hvis du vil bruge ISO-formatet 1 = Monday ... 7 = Sunday
i din day_of_week
felt, skal du binde phps date('N')
til din forespørgsel (eller brug Mysql's if-funktionen IF(DATE_FORMAT(NOW(), '%w') = 0, 7, DATE_FORMAT(NOW(), '%w'))
, men det er grimt)