I have the following simple query which works perfectly in MySQL;
select * from client_contact
where date_format(client_next_contact_on, '%Y-%m-%d') = '2018-07-25'
I've then added this in my codeigniter query but the error I get is;
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''2018-07-25'' at line 3
SELECT * FROM (client_contact) WHERE dateformat(client_next_contact_on, '%Y-%m-%d') '2018-07-25'
By the looks of the above, it's missing the = in the query.
Here's my query in codeigniter;
$today = new DateTime();
$today_formatted = $today->format('Y-m-d');
$this->db->where('dateformat(client_next_contact_on, \'%Y-%m-%d\')', $today_formatted);
$return = $this->db->get('client_contact')->row_array();
If you're wondering why I need to use date_format, it's because it's stored as a date time in my database for other purposes. For this purpose, I need a list of clients that I need to contact today, regardless of the time.