Skip to content

Instantly share code, notes, and snippets.

@somoza
Created April 19, 2020 19:23
Show Gist options
  • Save somoza/023c21bdca180c4fa24d6d56c40851d6 to your computer and use it in GitHub Desktop.
Save somoza/023c21bdca180c4fa24d6d56c40851d6 to your computer and use it in GitHub Desktop.
Filter by DateTime using just date on Symfony 3.4
$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