Welcome Guest, Not a member yet? Register   Sign In
Using Native MySQL Functions With Active Record
#1

[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!
#2

[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');
#3

[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




Theme © iAndrew 2016 - Forum software by © MyBB