php codeigniter :获取在两个日期之间发布的数据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4875668/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 16:09:26  来源:igfitidea点击:

codeigniter : Getting data posted in between two dates

phpsqlcodeigniteractiverecord

提问by Thomas John

How can I retrieve data from the database by querying records between two dates using codeigniter's activerecord?

如何通过使用 codeigniter 的 activerecord 查询两个日期之间的记录来从数据库中检索数据?

thanks

谢谢

回答by Teej

This looks like what you need:

这看起来像你需要的:

$this->db->where('order_date >=', $first_date);
$this->db->where('order_date <=', $second_date);
return $this->db->get('orders');

回答by Chakradhar

Try This:

尝试这个:

$this->db->where('sell_date BETWEEN "'. date('Y-m-d', strtotime($start_date)). '" and "'. date('Y-m-d', strtotime($end_date)).'"');

Hope this will work

希望这会奏效

回答by Madhu

This worked great for me

这对我很有用

$this->db->where('sell_date BETWEEN "'. date('Y-m-d', strtotime($start_date)). '" and "'. date('Y-m-d', strtotime($end_date)).'"');

回答by jonmary karanzi

This worked for me:

这对我有用:

$this->db->where('RecordDate >=', '2018-08-17 00:00:00');
$this->db->where('RecordDate <=', '2018-10-04 05:32:56');

回答by DRO

If you want to compare SQL dates, you can try this:

如果你想比较 SQL 日期,你可以试试这个:

$this->db->select();
$this->db->from('table_name');
$this->db->where(' date_columnname >= date("'.$from.'")');
$this->db->where( 'date_columnname <= date("'.$to.'")');

That worked for me (PHP and MySQL).

这对我有用(PHP 和 MySQL)。

回答by drosanda

if you want to force using BETWEEN keyword on Codeigniter query helper. You can use where without escape false like this code. Works well on CI version 3.1.5. Hope its help someone.

如果您想在 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();
    }

回答by Vipin Choubey

Just simply write BETWEEN '{$startDate}' AND '{$endDate}' in where condition as

只需简单地写 BETWEEN '{$startDate}' AND '{$endDate}' 在 where 条件为

->where("date BETWEEN '{$startDate}' AND '{$endDate}'")

回答by abubakkar tahir

if you date filed is timestamp then this is the easy way to get record

如果您提交的日期是时间戳,那么这是获取记录的简单方法

$this->db->where('DATE(RecordDate) >=', date('Y-m-d',strtotime($startDate)));
$this->db->where('DATE(RecordDate) <=', date('Y-m-d',strtotime($endDate)));

回答by Pratik Butani

May this helpful to you.... With Join of Three Tables

可能这对你有帮助.... 三表的连接

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;
    }

回答by user28864

$query = $this->db
              ->get_where('orders',array('order_date <='=>$first_date,'order_date >='=>$second_date))
              ->result_array();