Welcome Guest, Not a member yet? Register   Sign In
Problem Using Active Record with MySQL DATE_FORMAT command
#1

[eluser]LynxCoder[/eluser]
Hi Guys,
I have the following code:

$this->db->select("imageid,imagedate,DATE_FORMAT(imagedate, %d-%m ) AS thisday, DATE_FORMAT(imagedate, '%Y' ) AS imageyear");
$this->db->from('images');
$this->db->where("DATE_FORMAT(imagedate, '%d-%m') = ", $usedate);
$this->db->where("imagedate <", $thisyear."-01-01");
$this->db->order_by('imageid desc');
$query=$this->db->get();

The SQL works fine when put into phpMyAdmin and executed as a pure SQL statement (admittedly without the CI Active Record code) but when I execute the above I get the following problem:



A Database Error Occurred
Error Number: 1054

Unknown column '"%d-%m"' in 'field list'

SELECT `imageid`, `imagedate`, DATE_FORMAT(imagedate, `"%d-%m"` ) AS thisday, DATE_FORMAT(imagedate, `"%Y"` ) AS imageyear FROM (`images`) WHERE DATE_FORMAT(imagedate, "%d-%m") = '19-12' AND `imagedate` < '2011-01-01' ORDER BY `imageid` desc

Now CI is adding extra `` around the date string. i've tried removeing the "" marks and still get the same error. CI is leading MySQL to think that %d-%m is a field name. Any thoughts on how I can get around it ... spent three hours playing with this today!

Cheers
Rich




Theme © iAndrew 2016 - Forum software by © MyBB