Skip to content

Instantly share code, notes, and snippets.

@ivoba
Created November 3, 2022 11:07
Show Gist options
  • Save ivoba/000816a698db76d8a50a3573ce56ef8e to your computer and use it in GitHub Desktop.
Save ivoba/000816a698db76d8a50a3573ce56ef8e to your computer and use it in GitHub Desktop.
DataTransformer to remove seconds for HTML5 datepicker with symfony forms
<?php
namespace App\Form;
use Symfony\Component\Form\DataTransformerInterface;
class DateTimeNoSecondsTransformer implements DataTransformerInterface
{
public function transform(mixed $value)
{
if (null === $value) {
return null;
}
return \DateTime::createFromFormat('Y-m-d H:i', $value->format('Y-m-d H:i'));
}
public function reverseTransform(mixed $value)
{
return $value;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment