Py学习  »  DATABASE

检查商店是否开门。MySQL node.js业务逻辑

JD333 • 5 年前 • 1299 次点击  

给用户一段时间,我想弄清楚商店是开着的还是关着的。

我的操作数据库小时数如下:

dayid | openTime | closeTime
  3       1500      2400
  4       1500      2400
  5       1500       100
  6       1500       200

dayid是星期日-星期六:分别为0-6。

打开时间和关闭时间范围在0-2400之间。

如果用户时间是周三1800,那就很容易了。这地方是开放的。但如果是周六凌晨1点呢?大于openTime返回false,小于closeTime检查返回true。false&true等于false。

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/57214
 
1299 次点击  
文章 [ 1 ]  |  最新文章 5 年前
Gordon Linoff
Reply   •   1 楼
Gordon Linoff    5 年前

你可以使用这样的逻辑:

where dayid = @dayid and
      ( (openTime < closeTime and @timetocheck between openTime and closeTime) or
        (openTime > closeTime and @timetocheck not between closeTime and openTime)
      )