Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony datetime field format

I have a datetime field in a form which I want to give format mask yyyy-mm-dd hh:mi, and I use the following code:

$builder->add('beginDate', 'datetime', array('widget' => 'single_text',
                                               'date_format' => 'yyyy-MM-dd  HH:i'))

But what I get in form field is something like this:

2014-08-25T22:37:37Z

I would like something like:

2014-08-25 22:37

Can I get this?

I've seen this and this but didn't find a real example for hours (24 hour format) and minutes

thank you

like image 373
K. Weber Avatar asked Aug 31 '14 20:08

K. Weber


2 Answers

Have you tried the following date_format in your datetime definition?

'yyyy-MM-dd HH:mm'

instead of what you have now:

'yyyy-MM-dd HH:i'

I think you're mixing PHP date format options with the RFC format options the symfony form builder expects, according to the documentation. Peruse the accepted RFC datetime formats to see how to tweak it.

like image 63
Leo Bedrosian Avatar answered Sep 25 '22 00:09

Leo Bedrosian


You should use the format option which accepts HTML5 DateTime format.

$builder->add(
    'beginDate',
    'datetime',
    array(
        'widget' => 'single_text',
        'format' => 'yyyy-MM-dd  HH:mm'
    )
)

The format option should be used instead of date_format when using widget = single_text.

like image 38
Egg Avatar answered Sep 27 '22 00:09

Egg