Created
April 19, 2020 19:23
-
-
Save somoza/023c21bdca180c4fa24d6d56c40851d6 to your computer and use it in GitHub Desktop.
Filter by DateTime using just date on Symfony 3.4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$builder->add('created', Filters\DateFilterType::class, array( | |
'widget' => 'single_text', | |
'label' => 'Fecha', | |
'html5' => false, | |
'attr' => ['class' => 'js-datepicker'], | |
'apply_filter' => function (QueryInterface $filterQuery, $field, $values) { | |
if (empty($values['value'])) { | |
return null; | |
} | |
$paramName = sprintf('p_%s', str_replace('.', '_', $field)); | |
// expression that represent the condition | |
$expression = $filterQuery->getExpr()->like($field, ':'.$paramName); | |
// expression parameters | |
$parameters = array($paramName => $values['value']->format('Y-m-d') . "%"); | |
return $filterQuery->createCondition($expression, $parameters); | |
}, | |
)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment