CodeIgniter Forums

Full Version: Using Native MySQL Functions With Active Record
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

I'm having some trouble mixing Active Record and MySQL functions. I'm just trying to
SELECT * FROM 'sometable' WHERE DATE('datetime_column') = CURDATE()

In other words, I only want to select items whose date (found in the 'datetime_column') is equal to today's date. Can I throw a standard MySQL function (like 'DATE()') into $this->db-where()? If so, what's the syntax? Quotations around the MySQL functions? Nothing seems to be working for me.

Or is there some other way to do this? I'm just trying to avoid $this->db->query() in favor of more strict active record.


El Forum

[eluser]Armchair Samurai[/eluser]
Set the third parameter in the where function to FALSE:
$this->db->where("DATE('datetime_column')", 'CURDATE()', FALSE);
$query = $this->db->get('sometable');

El Forum

hey, thanks for the response, that helped. Mike and I are working on this together. I split the fields in my database up to "date" (DATE) and "time" (TIME) and then:

$this->db->where('date', 'CURDATE()', FALSE);

and now it works!

I apologize because this was the biggest noob post ever (as well as my first). I appreciate the help though. -Emery