0

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

enter image description here

Please help me.

Thanks.

1 Answer 1

1

You want to have the declaration of the field similar to the following;

$fieldset->addField(
    'date_to',
    'date',
    [
        'name' => 'date_to',
        'label' => __('Start Time'),
        'title' => __('Start Time'),
        'date_format' => $this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT),
        'time_format' => $this->_localeDate->getTimeFormat(\IntlDateFormatter::SHORT),
        'class' => 'validate-date'
    ]
);

The important bits are the date_format and time_format keys.

2
  • Thank's Smartie, 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. May 17, 2016 at 22:11
  • @smartie,I want to display only time.Please suggest me.
    – akgola
    Apr 30, 2019 at 12:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.