简体   繁体   English

检查输入的日期时间是否在2个datetime值的范围之间

[英]check whether entered date time is between the range of 2 datetime values

I have table which contains 2 columns startdate and enddate for storing the start and end time of fun program in a particular venue.(Both columns are having format of datetime-format is 'Ymd H:i:s').When a user creates a program within this time limit or the end time of the program lies within the time limit but not the start time or the start time lies within the time limit but not the end time ,the program should not be inserted into the table showing an alert.I have written the query like this.But it doesn't work properly. 我有一个包含两列开始日期和结束日期的表,用于存储特定场所中娱乐节目的开始和结束时间(这两列的日期时间格式均为'Ymd H:i:s')。当用户创建时a program within this time limitthe end time of the program lies within the time limit but not the start time the start time lies within the time limit but not the end time ,该程序不应插入显示警报的表格中我写了这样的查询,但是不能正常工作。

SELECT * FROM tbl_venue WHERE venue_id='id' AND
((venue_start_datetime BETWEEN 'entered starttime' AND 'entered end time')
AND (venue_stop_datetime BETWEEN 'entered starttime' AND 'entered end time'))    

Thanks in advance. 提前致谢。

Try this: 尝试这个:

SELECT * 
FROM tbl_venue 
WHERE venue_id='id' AND
'entered starttime' >= venue_start_datetime
AND 'entered end time' <= venue_stop_datetime
AND 'entered starttime' <= 'entered end time'

You jast have to test if the entered startdate is between start and enddate or the entererd enddate is between start and enddate 您必须测试输入的开始日期是在开始和结束日期之间还是输入的结束日期是在开始和结束日期之间

SELECT * FROM tbl_venue WHERE venue_id='id' AND
('entered starttime' BETWEEN venue_start_datetime AND venue_stop_datetime
OR 'entered endtime' BETWEEN venue_start_datetime AND venue_stop_datetime)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM