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
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.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With