gpt4 book ai didi

php - 如何检查两个日期时间之间的日期时间是否重叠?

转载 作者:行者123 更新时间:2023-11-30 22:40:47 26 4
gpt4 key购买 nike

我正在开发一个 session 室预订系统,我会记录他们想要预订房间的时间段。现在我有两个时间段:2016-06-14 13:00:07 作为我数据库中的 from_time 字段和 2016-06-14 05:00:07 作为 to_time 字段。现在我必须检查给定时间段是否与数据库中的任何其他给定时间段重叠。怎么做?存储数据:我的代码:

$date = mysql_real_escape_string($_POST['date']);
$date1= mysql_real_escape_string($_POST['date1']);
$from=mysql_real_escape_string($_POST['date2']);
$to=mysql_real_escape_string($_POST['date3']);

$from = strtotime($from);
$to = strtotime($to);

$subfrom =strtotime('-30 minutes',$from);
$addto = strtotime('+30 minutes',$to);

$from = date('Y-m-d H:i:s',$from);
$to = date('Y-m-d H:i:s',$to);

$subfrom = date('Y-m-d H:i:s',$subfrom);
$addto = date('Y-m-d H:i:s',$addto);

$id = mysql_real_escape_string($_POST['faculty_id']);
$name = mysql_real_escape_string($_POST['faculty_name']);
$div = mysql_real_escape_string($_POST['division']);
$school = mysql_real_escape_string($_POST['s_name']);
$email = mysql_real_escape_string($_POST['email']);
$contact = mysql_real_escape_string($_POST['contact_no']);
$intercom = mysql_real_escape_string($_POST['intercom']);
$purpose = mysql_real_escape_string($_POST['purpose']);
if($purpose=='university lecture')
$purpose = "university lecture";
else if($purpose=='guest lecture')
$purpose = "guest lecture";
else if($purpose=='PHD Oral Exam')
$purpose = "PHD Oral Exam";
else if($purpose=='Placement Interview')
$purpose = "Placement Interview";
else if($purpose=='others')
$purpose = "others";

$reason = mysql_real_escape_string($_POST['reason']);

$sql = "insert into video_conf_room(employee_id, emp_name, division, s_name, email, contact_no, intercom, from_time, to_time, b_f_time, b_t_time, purpose, reason)
values('$id','$name','$div','$school','$email','$contact','$intercom','$from','$to','$subfrom','$addto','$purpose','$reason')";

$res = mysql_query($sql, $con) or die(mysql_error());
if($res)
{
echo "you have successfully booked the video comferencing room";
$message = "Following are the details for the video conferencing room registration booked recently \r\n Faculty id: ".$id."\r\nName: ".$name."\r\n Divison: "
.$div."\r\n School: ".$school."\r\n email: ".$email."\r\n Contact: ".$contact."\r\n Intercom no.: ".$intercom."\r\n Purpose: ".
$purpose."\r\n Reason: ".$reason."\r\n Booked from :".$subfrom."Booked till :".$addto;
$message = wordwrap($message, 70, "\r\n");

mail('mymail@domain.com','Video conferencing room registration',$message);


}

最佳答案

你会像这样运行一个查询......

SELECT * FROM `video_conf_room` WHERE ('$from' BETWEEN `from_time` AND `to_time`) OR ('$to' BETWEEN `from_time` AND `to_time`)

...如果您得到任何结果,那么此时会预订另一次 session ,您不会插入预订。

关于php - 如何检查两个日期时间之间的日期时间是否重叠?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31193062/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com