CodeIgniter Forums

Full Version: Using DATE_FORMAT and Active Records
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]haydenp[/eluser]
Hi

I'm trying my best to stick to the Active Record approach but sometimes it puts up a bit of a fight! For instance ... has anyone tried to format a date as per below:

Code:
$this->db->select("table_name.id, DATE_FORMAT(table_name.x_date, '%d %b %Y') as y_date");

Trying my best to stick to the Active Record approach I have attempted a number of variations of the above code without success ...

Has anyone else managed to get this to work using the Active Record approach?

PS: The code above spews out
Code:
... DATE_FORMAT(table_name.x_date, `'%d` %b %Y') ...
and kicks up a 1064 You have an error in your SQL syntax ...

NOTE: As a "work-around" one can add 'FALSE' as a second parameter to the '$this->db->select' to stop CI from adding the back-ticks ... not ideal but it works!

El Forum

[eluser]Thorpe Obazee[/eluser]
[quote author="haydenp" date="1244594672"]
NOTE: As a "work-around" one can add 'FALSE' as a second parameter to the '$this->db->select' to stop CI from adding the back-ticks ... not ideal but it works![/quote]

It's what the user_guide tells you to do when you come across this.