dbQuery with condition and date_format() I have a request that should return a list of nodes that have a creation date &lt;= 6 months. It works well with $query-&gt;where() but I want to use $query-&gt;condition ().

Query with CONDITION:

$query = db_select('node', 'n');
$query-&gt;innerJoin('field_data_field_date_de_publication_news', 'fn', 'fn.entity_id = n.nid');
$query-&gt;innerJoin('field_data_body', 'fb', 'fb.entity_id = n.nid');
$query-&gt;fields('n', array('title', 'status', 'nid'));
$query-&gt;fields('fn', array('field_date_de_publication_news_value') );
$query-&gt;condition('fn.field_date_de_publication_news_value', 'MONTH(NOW())-6', '&lt;='); 
$query-&gt;orderBy('fn.field_date_de_publication_news_value', 'DESC');    
$rows = $query-&gt;execute(); 


But if I replace CONDITION with WHERE it works:

$query-&gt;where(" MONTH(fn.field_date_de_publication_news_value) &lt;= MONTH(NOW())-6" );


I also tried:

$query-&gt;fields('fn', array("DATE_FORMAT(FROM_UNIXTIME(field_date_de_publication_news_value), '%m')") );
condition() can only be used for simple expressions (=, &gt;, &lt;, &lt;&gt;, BETWEEN, LIKE, and a few others).

Using where() as you are already is the correct way to construct a more complex query.