phpdatetimecodeignitercodeigniter-3codeigniter-query-builder

CodeIgniter query to get rows with datetime value not after a specified date


I have data looking like this

enter image description here

I want show all before 01-08-2018 record (included 01-08-2018) but currently need to fill in 02-08-2018, then able to found 01-08-2018 record

I've tried get data like this this is my where clause:

$this->db->where("a.created_date <=",date("Y-m-d", strtotime($end_date)));

but its only show data before 01-08-2018 record not included 01-08-2018


Solution

  • Hope this will help you :

    Add date function before a.created_date like this :

    $this->db->where("date(a.created_date) <= ", date("Y-m-d", strtotime($end_date)));
    

    For more : https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html