如何检查日期范围是否存在 [英] How can I check for date range exists

查看:60
本文介绍了如何检查日期范围是否存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您可能已经从标题中注意到了,我的问题很难表达,但是有问题:

As you may have noticed from title, my question is quite difficult to express, but there is problem:

我有一些数据的MySQL表:

I have MySQL table with some data:

在注册表中,我必须指定预订的开始和结束时间.如何检查指定时间是否已经注册了预定.例如,我不应该放置从13:20开始到15:00等结束的新预订.

In registration form I have to specify reservation start and end times. How can I check, whether there is already registered reservation for specified time or not. For example I should not be able to put new reservation which starts at 13:20 and ends at 15:00 etc.

推荐答案

如果要创建的新保留的开始或结束位于当前范围内,则应阻止该保留.使用:reservationStart:reservationEnd作为这些日期,您可以查询:

If either the start or the end of the new reservation you want to create is inside a current range, the reservation should be blocked. Using :reservationStart and :reservationEnd as these dates, you could query:

SELECT *
FROM   reservations
WHERE  :reservationStart BETWEEN reservation_from AND reservation_to OR
       :reservationEnd BETWEEN reservation_from AND reservation_to OR

这篇关于如何检查日期范围是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆