Answer the question
In order to leave comments, you need to log in
Bitrix how to implement a filter by custom field?
Good afternoon!
Faced the problem of filtering HighloadBlock by date range in Bitrix.
How can I filter by date range?
Code example (does not filter):
use Bitrix\HighloadBlock as HL;
use Bitrix\Main\Entity;
CModule::IncludeModule('highloadblock');
$hlbl = 2;
$hlblock = HL\HighloadBlockTabke::getById($hlbl)->fetch();
$entity = HL\HighloadBlockTable::compileEntity($hlblock);
$entity_data = $entity->getDataClass();
$dbData = $entity_data::getlist(array(
'select' => array('*'),
'order' => array('UF_CATEGORIAY'=>'ASC'),
'filter' => array(
'>=UF_DATE' => '2017-03-01 18:00:00',
'<=UF_DATE' => '2017-01-01 18:00:00'
)
));
while($data = $dbData->fetch())
{
echo '<pre>';print_r($data);echo'</pre>';
}
Answer the question
In order to leave comments, you need to log in
First, the site format is used instead of Ymd H:i:s.
Second, use \Bitrix\Main\Type\DateTime
$dbData = $entity_data::getlist(array(
'select' => array('*'),
'order' => array('UF_CATEGORIAY'=>'ASC'),
'filter' => array(
'>=UF_DATE' => \Bitrix\Main\Type\DateTime::createFromUserTime('01.01.2017 18:00:00'),
'<=UF_DATE' => \Bitrix\Main\Type\DateTime::createFromUserTime('03.01.2017 18:00:00')
)
));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question