Hari
Hari

Reputation: 301

timestamp to date format is not working in twig

I'm trying to convert the timestamp value to date format in twig file but I'm getting the following error.

{{ form_row(form.startDate)|date("m/d/Y") }}

Error:

An exception has been thrown during the rendering of a template ("DateTime::__construct(): Failed to parse time string (<div><label for="event_setup_startDate" class="required">Start date</label><input type="text" id="event_setup_startDate" name="event_setup[startDate]" required="required" class="datetimepicker" value="1478257800" /></div>) at position 0 (<): Unexpected character")

Upvotes: 0

Views: 1558

Answers (1)

Matteo
Matteo

Reputation: 39430

You should pass the option format to the DateTime form field, in the form builder as example:

$builder->add('startDate', DateType::class, array(
    'format' => 'm/d/Y',
));

Or pass to the twig option as example:

{{ form_row(form.startDate, {'format': 'm/d/Y'}) }}

Hope this help

Upvotes: 3

Related Questions