cancel
Showing results for 
Search instead for 
Did you mean: 

How add time to datepicker in backend ?

SOLVED

How add time to datepicker in backend ?

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.

1 ACCEPTED SOLUTION

Accepted Solutions

Re: How add time to datepicker in backend ?

Hi siyagh,

 

I use this code for my backend:

 

$dateFormat = $this->_localeDate->getDateFormat(\IntlDateFormatter:Smiley FrustratedHORT);
        $timeFormat = $this->_localeDate->getTimeFormat(\IntlDateFormatter:Smiley FrustratedHORT);
        
        $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

View solution in original post

3 REPLIES 3

Re: How add time to datepicker in backend ?

Hi siyagh,

 

I use this code for my backend:

 

$dateFormat = $this->_localeDate->getDateFormat(\IntlDateFormatter:Smiley FrustratedHORT);
        $timeFormat = $this->_localeDate->getTimeFormat(\IntlDateFormatter:Smiley FrustratedHORT);
        
        $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

Re: How add time to datepicker in backend ?

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.

Re: How add time to datepicker in backend ?

Sorry but i don't have it Smiley Very Happy.  I find solution by search ...