$query->join('field_data_field_amountpaid', 'amt', 'n.nid = amt.entity_id and amt.field_amountpaid_value >=500 and amt.field_amountpaid_value <=5000 '); //JOIN node with Body

This is my normal query how can I call this in entity query?

I tried this way;

$query->fieldCondition('field_amountpaid', 'value', array('501','5000'),'BETWEEN');

But it's not working. Any idea?

  • 1
    BETWEEN statements work fine for me in n EntityFieldQuery`, are you sure the data in the database is what you expect it to be? – Clive Feb 23 '12 at 17:18

I had the same problem than you, and was able to fix it. The real problem here is that the documentation does not provide any example.

As it was already mentioned, the BETWEEN will only work if you are using the same data types that are being stored.

In my case, the field i was searching was a date field that has a specific format. So instead of passing a timestamp i had to format that date and then pass it.

//something like
start_date = (isset($_GET['startDate'])) ?  date('Y-m-d/T00:00:00',strtotime($_GET['startDate'])) : null;
        $end_date = (isset($_GET['endDate'])) ? date('Y-m-d/T00:00:00',strtotime($_GET['endDate'])) : null;

        if (isset($start_date) && isset($end_date)) {
           $query->fieldCondition('field_publication_date', 'value', array($start_date,$end_date), 'BETWEEN');

Hope this helps you!


'BETWEEN': This operator expects $value to be an array of two literals of the same type as the column.

DId you make sure that your "value" and your array types were the same?


Try also different type format like this: array(501,5000).

Try also with small letters 'between'.

Make sure there is some data in that table.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.