2 added 793 characters in body
source | link

I'm trying to add following mysql condition:

WHERE       DAYOFYEAR(curdate()) <= DAYOFYEAR(DATE_ADD(FROM_UNIXTIME(field_birthday_value, '%y-%m-%d'), INTERVAL (YEAR(NOW()) - YEAR(FROM_UNIXTIME(field_birthday_value, '%y-%m-%d'))) YEAR))
AND         DAYOFYEAR(curdate()) +7 >= DAYOFYEAR(DATE_ADD(FROM_UNIXTIME(field_birthday_value, '%y-%m-%d'), INTERVAL (YEAR(NOW()) - YEAR(FROM_UNIXTIME(field_birthday_value, '%y-%m-%d'))) YEAR))

To my db_select $query->condition:

//Build query
$query = db_select('users', 'u');
$query->leftJoin('field_data_field_birthday', 'fb', 'u.uid = fb.entity_id');
$query->condition('THE CONDITION MUST BE ADDED HERE');
$query->fields('u', array('uid', 'name'));
$query->fields('fb', array('field_birthday_value'));
$query->range(0,5);
$users = $query->execute();

But i can't figure out how. Simple conditions like =, <> are easy. But i got no clue how to add my more complex condition.

Thx

EDIT: Should pay more attention to the documentation :). Ty!

//Build query
$query = db_select('users', 'u');
$query->leftJoin('field_data_field_birthday', 'fb', 'u.uid = fb.entity_id');
$query->where("DAYOFYEAR(curdate()) <= DAYOFYEAR(DATE_ADD(FROM_UNIXTIME(fb.field_birthday_value, '%y-%m-%d'), INTERVAL (YEAR(NOW()) - YEAR(FROM_UNIXTIME(fb.field_birthday_value, '%y-%m-%d'))) YEAR))");
$query->where("DAYOFYEAR(curdate()) +7 >= DAYOFYEAR(DATE_ADD(FROM_UNIXTIME(fb.field_birthday_value, '%y-%m-%d'), INTERVAL (YEAR(NOW()) - YEAR(FROM_UNIXTIME(fb.field_birthday_value, '%y-%m-%d'))) YEAR))");
$query->fields('u', array('uid', 'name'));
$query->fields('fb', array('field_birthday_value'));
$query->range(0,5);
$users = $query->execute();

I'm trying to add following mysql condition:

WHERE       DAYOFYEAR(curdate()) <= DAYOFYEAR(DATE_ADD(FROM_UNIXTIME(field_birthday_value, '%y-%m-%d'), INTERVAL (YEAR(NOW()) - YEAR(FROM_UNIXTIME(field_birthday_value, '%y-%m-%d'))) YEAR))
AND         DAYOFYEAR(curdate()) +7 >= DAYOFYEAR(DATE_ADD(FROM_UNIXTIME(field_birthday_value, '%y-%m-%d'), INTERVAL (YEAR(NOW()) - YEAR(FROM_UNIXTIME(field_birthday_value, '%y-%m-%d'))) YEAR))

To my db_select $query->condition:

//Build query
$query = db_select('users', 'u');
$query->leftJoin('field_data_field_birthday', 'fb', 'u.uid = fb.entity_id');
$query->condition('THE CONDITION MUST BE ADDED HERE');
$query->fields('u', array('uid', 'name'));
$query->fields('fb', array('field_birthday_value'));
$query->range(0,5);
$users = $query->execute();

But i can't figure out how. Simple conditions like =, <> are easy. But i got no clue how to add my more complex condition.

Thx

I'm trying to add following mysql condition:

WHERE       DAYOFYEAR(curdate()) <= DAYOFYEAR(DATE_ADD(FROM_UNIXTIME(field_birthday_value, '%y-%m-%d'), INTERVAL (YEAR(NOW()) - YEAR(FROM_UNIXTIME(field_birthday_value, '%y-%m-%d'))) YEAR))
AND         DAYOFYEAR(curdate()) +7 >= DAYOFYEAR(DATE_ADD(FROM_UNIXTIME(field_birthday_value, '%y-%m-%d'), INTERVAL (YEAR(NOW()) - YEAR(FROM_UNIXTIME(field_birthday_value, '%y-%m-%d'))) YEAR))

To my db_select $query->condition:

//Build query
$query = db_select('users', 'u');
$query->leftJoin('field_data_field_birthday', 'fb', 'u.uid = fb.entity_id');
$query->condition('THE CONDITION MUST BE ADDED HERE');
$query->fields('u', array('uid', 'name'));
$query->fields('fb', array('field_birthday_value'));
$query->range(0,5);
$users = $query->execute();

But i can't figure out how. Simple conditions like =, <> are easy. But i got no clue how to add my more complex condition.

Thx

EDIT: Should pay more attention to the documentation :). Ty!

//Build query
$query = db_select('users', 'u');
$query->leftJoin('field_data_field_birthday', 'fb', 'u.uid = fb.entity_id');
$query->where("DAYOFYEAR(curdate()) <= DAYOFYEAR(DATE_ADD(FROM_UNIXTIME(fb.field_birthday_value, '%y-%m-%d'), INTERVAL (YEAR(NOW()) - YEAR(FROM_UNIXTIME(fb.field_birthday_value, '%y-%m-%d'))) YEAR))");
$query->where("DAYOFYEAR(curdate()) +7 >= DAYOFYEAR(DATE_ADD(FROM_UNIXTIME(fb.field_birthday_value, '%y-%m-%d'), INTERVAL (YEAR(NOW()) - YEAR(FROM_UNIXTIME(fb.field_birthday_value, '%y-%m-%d'))) YEAR))");
$query->fields('u', array('uid', 'name'));
$query->fields('fb', array('field_birthday_value'));
$query->range(0,5);
$users = $query->execute();
1
source | link

Complex condition drupal query

I'm trying to add following mysql condition:

WHERE       DAYOFYEAR(curdate()) <= DAYOFYEAR(DATE_ADD(FROM_UNIXTIME(field_birthday_value, '%y-%m-%d'), INTERVAL (YEAR(NOW()) - YEAR(FROM_UNIXTIME(field_birthday_value, '%y-%m-%d'))) YEAR))
AND         DAYOFYEAR(curdate()) +7 >= DAYOFYEAR(DATE_ADD(FROM_UNIXTIME(field_birthday_value, '%y-%m-%d'), INTERVAL (YEAR(NOW()) - YEAR(FROM_UNIXTIME(field_birthday_value, '%y-%m-%d'))) YEAR))

To my db_select $query->condition:

//Build query
$query = db_select('users', 'u');
$query->leftJoin('field_data_field_birthday', 'fb', 'u.uid = fb.entity_id');
$query->condition('THE CONDITION MUST BE ADDED HERE');
$query->fields('u', array('uid', 'name'));
$query->fields('fb', array('field_birthday_value'));
$query->range(0,5);
$users = $query->execute();

But i can't figure out how. Simple conditions like =, <> are easy. But i got no clue how to add my more complex condition.

Thx