Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
mysql获取自由时间设置会议_Mysql_Sql_Time - Fatal编程技术网

mysql获取自由时间设置会议

mysql获取自由时间设置会议,mysql,sql,time,Mysql,Sql,Time,我在MySQL中有一个带有 date starttime endtime 11/2/2014 10:00:00 10:45:00 11/2/2014 10:45:00 11:15:00 11/2/2014 11:45:00 12:15:00 11/2/2014 12:15:00 13:30:00 我需要sql查询返回我可以将新会议设置为30分钟的时间 $array_time = array(); $query = "SELECT start

我在MySQL中有一个带有

     date  starttime    endtime 
11/2/2014   10:00:00   10:45:00
11/2/2014   10:45:00   11:15:00
11/2/2014   11:45:00   12:15:00
11/2/2014   12:15:00   13:30:00
我需要sql查询返回我可以将新会议设置为30分钟的时间

$array_time = array();

$query = "SELECT starttime, endtime FROM table";
$result = $mysqli->query($query);

//fetch result
while ($array_time[] = $result->fetch_assoc()) {}

/*
$array_time = Array (
  ...
  1 => array('starttime' => 10:45:00, 'endtime' => 11:15:00)
  2 => array('starttime' => 11:45:00, 'endtime' => 12:15:00)
  ...
)
*/

//array of free time for your meeting
$free_time = array();

foreach($array_time as $i => $row){
  if($i > 0) {
    //if this is not the first time row

    //get this row starttime
    $this_starttime = strtotime($row['starttime']);

    //and the last endtime
    $prev_endtime = strtotime($array_time[$i-1]['endtime']);

    //get the difference
    $diff = $this_starttime - $prev_endtime;

    //if difference is more or equal than 30 minutes
    if($diff >= strtotime('30 minutes')) {
      $free_time[] = array('starttime' => $row['starttime'], $array_time[$i-1]['endtime']);
    }
  }
}
我认为在MySQL查询中无法做到这一点,所以PHP可以帮助您。 希望它能工作,我还没有测试出来


但是试着用另一种方式保存你的数据,这不是很有效,如您所见。

例如,您的意思是插入包含以下信息的新行:
11/2/2014 11:15:00 11:45:00
?谢谢您的回答。在我的示例中,我需要it返回11:15:00,因为之后的唯一会议是在11:45,我可以在11:15:00到11:45:00之间设置一个30分钟的会议你!我在等你,非常感谢。你帮了大忙。@rafiamar如果我帮了忙,请接受我的回答。谢谢!