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.

0

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.

| improve this answer | |
  • 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. – Abdelouahed Siyagh May 17 '16 at 22:11
  • @smartie,I want to display only time.Please suggest me. – akgola Apr 30 '19 at 12:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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