Need to pick a month, and return a valid date


Hello support,

I need the user to pick up a month, but as a result I wish I had a valid date.
but the value is a string (ex : ‘November 2017’)

do I have to build a valid date from this string ? (I don’t really now how)
The resulting date could be the first day of the selected month for instance.

I’m trying this
$form->addField(‘date3’, [‘Calendar’, ‘type’ => ‘month’], [‘type’ => ‘date’]);

but it doesn’t work.
could someone be kind enough to help me ?



if you specify type = ‘date’ then it should properly read the date from the form and store it in PHP DateTime format

$form->addField('date3', null, ['type'=>'date']);


Thank you for answering.
But in your example, the field display a date choice, not a month choice.

What I’m looking for is a month picker that would return the first day of selected month as a valid date.
if possible, of course.


Oh, I see.

Well my suggestion then would be to reset the field type, so that it won’t typecast, and use calendar explicitly like you do.

Here the $calendar->options is passed to the JS widget so technically you can activate whatever option/mode you want. You can also patch up Calendar.php to allow this sort of behaviour and submit it as a pull-request.


Here’s what I did, and thank you for your help

// to display months in french I have to play with the js calendar options

$calOptions = [‘days’=>[‘D’, ‘L’, ‘Ma’, ‘Me’, ‘J’, ‘V’, ‘S’],
‘months’=>[‘Janvier’, ‘Février’, ‘Mars’, ‘Avril’, ‘Mai’, ‘Juin’, ‘Juillet’, ‘Août’, ‘Septembre’, ‘Octobre’, ‘Novembre’, ‘Decembre’],
‘monthsShort’=>[‘Jan’, ‘Fev’, ‘Mar’, ‘Avr’, ‘Mai’, ‘Juin’, ‘Juil’, ‘Aou’, ‘Sep’, ‘Oct’, ‘Nov’, ‘Dec’],
‘am’=> ‘AM’,
‘pm’=> ‘PM’

$month = $form->addField(‘month’,[‘Calendar’,‘type’=>‘month’,‘options’=>[‘firstDayOfWeek’=>1,‘text’=>$calOptions]]);

on a submit, I get the “text” value of the field
$sMonth = $_GET[‘MONTH’];

$datfmt = \IntlDateFormatter::create(‘fr_FR’, null, null, null, null, ‘LLLL y’); // from french text back to timestamp
$dMonth = $datfmt->parse($sMonth); //timestamp containing the first day of month