I'am using magento 2.0.5 and I want to add date field with time which saves date as well as time in database for entity. I had tried this code to add new field in my module.
$fieldset->addField('enddate', 'date', array( 'name' => 'enddate', 'label' => __('End date'), 'title' => __('End date'), 'format' => 'yy-mm-dd H:i:s', 'input_format' => 'yy-mm-dd H:i:s', 'required' => true, ) );
but this gives me only date to select not time
Please help me.
Thanks.
Solved! Go to Solution.
Hi siyagh,
I use this code for my backend:
$dateFormat = $this->_localeDate->getDateFormat(\IntlDateFormatter:HORT);
$timeFormat = $this->_localeDate->getTimeFormat(\IntlDateFormatter:HORT);
$fieldset->addField(
'start_time',
'date',
[
'name' => 'start_time',
'label' => __('Start At'),
'title' => __('Start At'),
'required' => true,
'date_format' => $dateFormat,
'time_format' => $timeFormat,
]
);
and it show like this:
Hope it help you
Hi siyagh,
I use this code for my backend:
$dateFormat = $this->_localeDate->getDateFormat(\IntlDateFormatter:HORT);
$timeFormat = $this->_localeDate->getTimeFormat(\IntlDateFormatter:HORT);
$fieldset->addField(
'start_time',
'date',
[
'name' => 'start_time',
'label' => __('Start At'),
'title' => __('Start At'),
'required' => true,
'date_format' => $dateFormat,
'time_format' => $timeFormat,
]
);
and it show like this:
Hope it help you
Thank's Rubelia, your answer helped me.
I looked in the documentation section that talks about programming forms part of the administration but I have not found anything, if you have links, thank you.
Sorry but i don't have it . I find solution by search ...