Php 获取两个日期之间发布的数据
如何通过使用CodeIgniter的activerecord查询两个日期之间的记录来从数据库检索数据?这看起来像是您需要的:Php 获取两个日期之间发布的数据,php,sql,codeigniter,activerecord,Php,Sql,Codeigniter,Activerecord,如何通过使用CodeIgniter的activerecord查询两个日期之间的记录来从数据库检索数据?这看起来像是您需要的: $this->db->where('order_date >=', $first_date); $this->db->where('order_date <=', $second_date); return $this->db->get('orders'); $this->db->where('order\u date>=
$this->db->where('order_date >=', $first_date);
$this->db->where('order_date <=', $second_date);
return $this->db->get('orders');
$this->db->where('order\u date>=',$first\u date);
$this->db->where('order\u date试试这个:
$this->db->where('sell_date BETWEEN "'. date('Y-m-d', strtotime($start_date)). '" and "'. date('Y-m-d', strtotime($end_date)).'"');
希望这能起作用希望这对你有所帮助。。。。
三个表的连接
public function get_details_beetween_dates()
{
$from = $this->input->post('fromdate');
$to = $this->input->post('todate');
$this->db->select('users.first_name, users.last_name, users.email, groups.name as designation, dailyinfo.amount as Total_Fine, dailyinfo.date as Date_of_Fine, dailyinfo.desc as Description')
->from('users')
->where('dailyinfo.date >= ',$from)
->where('dailyinfo.date <= ',$to)
->join('users_groups','users.id = users_groups.user_id')
->join('dailyinfo','users.id = dailyinfo.userid')
->join('groups','groups.id = users_groups.group_id');
/*
$this->db->select('date, amount, desc')
->from('dailyinfo')
->where('dailyinfo.date >= ',$from)
->where('dailyinfo.date <= ',$to);
*/
$q = $this->db->get();
$array['userDetails'] = $q->result();
return $array;
}
public函数获取日期之间的详细信息()
{
$from=$this->input->post('fromdate');
$to=$this->input->post('todate');
$this->db->select('users.first\u name,users.last\u name,users.email,groups.name作为指定,dailyinfo.amount作为总罚款,dailyinfo.date作为罚款的日期,dailyinfo.desc作为说明')
->来自('用户')
->其中('dailyinfo.date>=',$from)
->其中('dailyinfo.date=',$from)
->其中('dailyinfo.date$query=$this->db
->获取位置('orders',数组('order\u date='=>$second\u date))
->结果_数组();
这对我来说非常有效
$this->db->where('sell_date BETWEEN "'. date('Y-m-d', strtotime($start_date)). '" and "'. date('Y-m-d', strtotime($end_date)).'"');
如果要比较SQL日期,可以尝试以下方法:
$this->db->select();
$this->db->from('table_name');
$this->db->where(' date_columnname >= date("'.$from.'")');
$this->db->where( 'date_columnname <= date("'.$to.'")');
$this->db->select();
$this->db->from('table_name');
$this->db->where('date\u columnname>=date(“.$from.”));
$this->db->where('date\u columnname如果您想在Codeigniter查询帮助器上强制使用BETWEEN关键字。您可以像下面的代码一样使用where而不使用escape false。在CI版本3.1.5上运行良好。希望它能对其他人有所帮助
if(!empty($tglmin) && !empty($tglmax)){
$this->db->group_start();
$this->db->where('DATE(create_date) BETWEEN "'.$tglmin.'" AND "'.$tglmax.'"', '',false);
$this->db->group_end();
}
这对我很有用:
$this->db->where('RecordDate >=', '2018-08-17 00:00:00');
$this->db->where('RecordDate <=', '2018-10-04 05:32:56');
$this->db->where('RecordDate>=','2018-08-17 00:00:00');
$this->db->where('RecordDate只需在where条件下在'{$startDate}'和'{$endDate}'之间写入即可
作为
如果您的日期字段是数据库中的时间戳,那么这是获取记录的简单方法
$this->db->where('DATE(RecordDate) >=', date('Y-m-d',strtotime($startDate)));
$this->db->where('DATE(RecordDate) <=', date('Y-m-d',strtotime($endDate)));
$this->db->where('DATE(RecordDate)>=',DATE('Y-m-d',strottime($startDate));
$this->db->where('日期(记录日期)请进一步解释,如果您尝试过任何操作,请发布代码。我不知道您在说什么。您是否尝试在两个日期之间从数据库中提取数据?是的,我尝试使用codeigniter在两个日期之间从数据库中提取数据quries@ThorpeObazee如果我有两个号码,并且想知道输入的号码在哪呢介于两者之间?我觉得=
可能是错误的,但我不知道它们实际包含哪些值。
->where("date BETWEEN '{$startDate}' AND '{$endDate}'")
$this->db->where('DATE(RecordDate) >=', date('Y-m-d',strtotime($startDate)));
$this->db->where('DATE(RecordDate) <=', date('Y-m-d',strtotime($endDate)));