1
我正在致力于会议室预订系统,我花了他们想预订房间的时间段。现在我有两个时间段: 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('[email protected]','Video conferencing room registration',$message);
}
当我试图在我的查询中实现这个时,它总是显示日期时间重叠! '$ reason = mysql_real_escape_string($ _ POST ['reason']); $ sql1 =“SELECT * FROM'video_conf_room' WHERE('from''from_time'和'to_time')或('$ to'BETWEEN from_time' AND'to_time')”; $ response = mysql_query($ sql1,$ con)或die(mysql_error()); if(!$ response){ //执行注册查询 } else echo“Time overlapped”;' 它总是显示“时间重叠” –
请告诉我应该做什么修改? –