0

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")

2
  • You are passing the HTML code generated by the form_row function to the date constructor. Are you using a framework? Commented Nov 4, 2016 at 7:14
  • @Matteo. I'm using symfony framework. The datetype is set is string and trying to conver it to datetime format. Commented Nov 4, 2016 at 7:43

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.