Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/56.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
Php 在codeigniter中获取两个日期范围之间的数据_Php_Mysql_Codeigniter_Datetime - Fatal编程技术网

Php 在codeigniter中获取两个日期范围之间的数据

Php 在codeigniter中获取两个日期范围之间的数据,php,mysql,codeigniter,datetime,Php,Mysql,Codeigniter,Datetime,我正在尝试获取日期之间的数据。从日期选择器中选择日期。格式类似于2020年4月13日-2020年4月13日选择日期选择器。我的问题是这样的 public function reservation($reservation) { $this->db->select("*"); $this->db->from('details'); $this->db->where("DATE_FORMAT(date,'%Y-%m-%d') &g

我正在尝试获取日期之间的数据。从日期选择器中选择日期。格式类似于2020年4月13日-2020年4月13日选择日期选择器。我的问题是这样的

 public function reservation($reservation)
    {
    $this->db->select("*");
    $this->db->from('details');
    $this->db->where("DATE_FORMAT(date,'%Y-%m-%d') > '$reservation'");

        $query = $this->db->get();
        return $query->result();
    } 

我希望这对你有用

 public function reservation($first_date,$second_date)
 {
    $this->db->select("*");
    $this->db->from('details');
    $this->db->where("DATE_FORMAT(date,'%Y-%m-%d') >='$first_date'");
    $this->db->where("DATE_FORMAT(date,'%Y-%m-%d') <='$second_date'");
    $query = $this->db->get();
    return $query->result();
 }
公共功能预订($first\u date,$second\u date)
{
$this->db->select(“*”);
$this->db->from('details');
$this->db->where(“日期格式(日期,%Y-%m-%d')>=“$first\u日期”);
$this->db->where(“日期\格式(日期,%Y-%m-%d))试试这个:

$this->db->where("DATE_FORMAT(start_date,'%Y-%m-%d')",'>=',$first_date)
->where("DATE_FORMAT(end_date,'%Y-%m-%d')",'<=',$first_date);
$this->db->where(“日期格式(开始日期,%Y-%m-%d)”,“>=”,$first\u日期)

->其中(“日期格式(结束日期),%Y-%m-%d”),“我从日期选择器中选择日期,这类似于(04/13/2020-05/13/2020)格式,两个日期存储在同一个变量中,而不是单独的变量中。如$reservation=“04/13/2020-05/13/2020“不像$first_date=04/13/2020;$second_date=05/13/2020;您可以使用explode功能,在开始日期和结束日期示例中分隔两个日期:$str=“04/13/2020-05/13/2020”;打印(explode(“-”,$str));输出:数组([0]=>04/13/2020[1]=>05/13/2020)你需要根据问题编辑你的代码,使用explode后它对我有效function@jamilshah:听起来不错,这对你很有用。你可以把答案投上去,这样将来对别人也有帮助。