How to compare date from table with variable using db_query? I am trying to retrieve all records from a specific date, given the variable $date. I am using db_select and ->condition (due to a lot of joins).

I like to do something like:

-&gt;condition("`tableName`.`field_date_value` )", $date)


That doesn't return anything. Perhaps due to different time because field_date_value has a time set and $date hasn't. I looked into using a SQL functions like DATEDIFF, but it doesn't work for me.

How do I do this?
You are going to need to insure that the format of your $date variable is formatted exactly the same as the format of the date value in your database (field_date_value). For example, if your database is storing its date values in unixtime, then your $date variable needs to be unixtime. If your field_date_value field is storing mm:dd:yy hh:mm:ss, then your $date variable needs to reflect this same format accordingly. Refer to date() to formate your $date variable the appropriate way.

Once you've formatted your $date variable to the same formate of your sql data, you can run a condition method like this:

-&gt;condition("tablename.field_date_value", $date, "&gt;=")


This will query for everything equal to or greater than the specified $date value.