I am developing a custom module where there are many fields text,select,multiselect..etc in admin form.
Today I have added one field in admin of type time ,below is the code to add new field
$timeFormat = $this->_localeDate->getTimeFormat(\IntlDateFormatter::MEDIUM);
$actionTime = $fieldset->addField(
'action_time',
'time',
[
'name' => 'action_time',
'label' => __('Time'),
'class' => 'required-entry',
'required' => true,
'time_format'=> $timeFormat,
'time'=>true
]
);
and in installSchema.php I have put below code to add column in table
)->addColumn(
'action_time',
\Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP,
255,
['nullable' => false],
'Action Time'
)
Field created successfully but it throwing error when saving form.
Fatal error: Uncaught TypeError: DateTime::__construct() expects parameter 1 to be string, array given in /var/www/html/Magento2/vendor/magento/framework/Stdlib/DateTime.php:57 Stack trace: #0 /var/www/html/Magento2/vendor/magento/framework/Stdlib/DateTime.php(57): DateTime->__construct(Array) #1 /var/www/html/Magento2/vendor/magento/framework/DB/Adapter/Pdo/Mysql.php(2764): Magento\Framework\Stdlib\DateTime->formatDate(Array, true) #2 /var/www/html/Magento2/vendor/magento/framework/DB/Adapter/Pdo/Mysql.php(3001): Magento\Framework\DB\Adapter\Pdo\Mysql->formatDate(Array) #3 /var/www/html/Magento2/vendor/magento/framework/Model/ResourceModel/AbstractResource.php(183): Magento\Framework\DB\Adapter\Pdo\Mysql->prepareColumnValue(Array, Array) #4 /var/www/html/Magento2/vendor/magento/framework/Model/ResourceModel/Db/AbstractDb.php(541): Magento\Framework\Model\ResourceModel\AbstractResource->_prepareDataForTable(Object(Vendorname\Modulename\Model\Grid), 'manage_feed_dat...') #5 /var/www/html/Magento2/vendor/magento/framework in /var/www/html/Magento2/vendor/magento/framework/Stdlib/DateTime.php on line 57
I have debugged but not found any issue.Please help me.
'time_format' => 'hh:mm:ss'
or'time_format' => 'H:i:s',