i.am.michiel i.am.michiel - 1 year ago 63
PHP Question

How to display months in full text for Date fields in Symfony2?

When using Date field in forms with Symfony2, they are displayed in three different select boxes.
Something like :


What we would like to do is display the months in text
.... instead of 1,2,3...

How to force display in full text for the months dropdown ?

EDIT : Here is the code I use in my form class :

$builder->add('dateOfBirth', 'birthday', array(
'format' => 'dd - MM - yyyy',
'widget' => 'choice',
'years' => range(date('Y'), date('Y')-70)

EDIT2 : Image showing F

enter image description here

Answer Source

Look at the code of the DateType class, it has a format option:

$allowedFormatOptionValues = array(

        // If $format is not in the allowed options, it's considered as the pattern of the formatter if it is a string
        if (!in_array($format, $allowedFormatOptionValues, true)) {
            if (is_string($format)) {
                $defaultOptions = $this->getDefaultOptions($options);

                $format = $defaultOptions['format'];
                $pattern = $options['format'];
            } else {
                throw new CreationException('The "format" option must be one of the IntlDateFormatter constants (FULL, LONG, MEDIUM, SHORT) or a string representing a custom pattern');

$formatter = new \IntlDateFormatter(


$builder->add('dateOfBirth', 'birthday', array(
    'format' => 'dd - MMMM - yyyy',
    'widget' => 'choice',
    'years' => range(date('Y'), date('Y')-70)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download