user3396420
user3396420

Reputation: 840

Symfony2 datetime field form

I have a Symfony2 application which receive a JSON data in a form. One of the field is a date time. If I renderize the field form in this way:

->add('startDate', 'date', array(
        'widget' => 'single_text',
        'format' => 'yyyy-MM-dd HH:mm:ss'))

This accept something like:

"startDate": "2015-05-03 12:30:00"

But I need to introduce a datetime in this way:

"startDate": "2015-05-12T15:43:00+0200"

How can I set this format in the field?

Upvotes: 0

Views: 1271

Answers (1)

pabgaran
pabgaran

Reputation: 773

On http://php.net/manual/en/function.date.php

"c" => ISO 8601 date (added in PHP 5) => 2004-02-12T15:19:21+00:00

Try this:

->add('startDate', 'date', array(
    'widget' => 'single_text',
    'format' => 'c'))

I hope it helps.

Upvotes: 3

Related Questions