开发者

selecting current match from the cricket schedule using mysql query

I have a cricket schedule and i need to select the matches of the current day just half an hour before the match starts and the selection should last until the 2 hours past the end of the match , this should be done in a single query i have used the following query but it is not working accurately...

SELECT * FROM `schedule` WHERE  
   date1  BETWEEN DATE_SUB开发者_运维百科(NOW(), INTERVAL 30 MInute) 
              AND DATE_ADD(NOW(), INTERVAL 10 HOUR)


If you want to display all scheduled matches from half an hour before they start until 2 hours after they end, and all mathces have a duration of 12 hours, then you need to show all matches within a 14,5 hours interval, and not a 10,5 hours interval as your current code does:

SELECT * FROM `schedule` 
WHERE NOW() BETWEEN DATE_SUB(date1, INTERVAL 30 Minute) 
                AND DATE_ADD(date1, INTERVAL 14 HOUR)

Furthermore, you should compare the current time (NOW()) to the start time and end time of the game, not the other way round.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜