CodeIgniter Forums
Using Native MySQL Functions With Active Record - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Using Native MySQL Functions With Active Record (/thread-9408.html)



Using Native MySQL Functions With Active Record - El Forum - 06-24-2008

[eluser]MCrittenden[/eluser]
I'm having some trouble mixing Active Record and MySQL functions. I'm just trying to
Code:
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.

Thanks!


Using Native MySQL Functions With Active Record - El Forum - 06-24-2008

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



Using Native MySQL Functions With Active Record - El Forum - 06-24-2008

[eluser]emdog4[/eluser]
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:

Code:
$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