-3
$begin = new DateTime( date ( "Y-m-d",strtotime( $results->arrival ) ) );
$end = new DateTime( date ( "Y-m-d",strtotime( $results->departure ) ) );

$interval = DateInterval::createFromDateString('1 day');
$period = new DatePeriod($begin, $interval, $end);

foreach ( $period as $dt ) {
    $begin = $results->arrival;
    $end = $results->departure;


    if($begin == $results->arrival &&  $end == $results->departure ){
        echo 'This date is not available';
    } else {
        echo '<script type="text/javascript">$(\'#myForm\').submit();</script>';
    }
}
4

1 回答 1

0

创建这样的查询(如果您使用的是 mysql)。只需使用两个日期调用此函数。

 public function is_booked_date($check_in_date, $check_out_date)
    {
        $query = "SELECT count(id) FROM booking 
        where ((check_in_date BETWEEN '" . $check_in_date . "' AND '" . $check_out_date . "' 
        OR check_out_date  BETWEEN '" . $check_in_date . "' AND '" . $check_out_date . "') 
        OR('$check_in_date' <= check_in_date AND '$check_out_date' >= check_in_date)) ;"; 

        return $this -> db -> query($query) -> result();

    }

像这样调用函数

$check_in_date='';// your date
$check_out_date='';//your date
if($this->is_booked_date($check_in_date, $check_out_date))
{
  //Date already booked

}
else
{
   //New booking possible
}
于 2013-06-26T07:38:27.713 回答