I have tried to create datetime attribute in Magento 2. Below is my script:
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
$eavSetup->removeAttribute(\Magento\Catalog\Model\Product::ENTITY, 'course_start_datetime');
$eavSetup->addAttribute(
\Magento\Catalog\Model\Product::ENTITY,
'course_start',
[
'group' => 'Custom Attribute',
'label' => 'Enable Start Date',
'type' => 'datetime',
'input' => 'date',
'input_renderer' => 'Velanapps\Test\Block\Adminhtml\Form\Element\Datetime',
'class' => 'validate-date',
'backend' => 'Magento\Catalog\Model\Attribute\Backend\Startdate',
'required' => false,
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
'visible' => true,
'required' => false,
'user_defined' => true,
'default' => '',
'searchable' => true,
'filterable' => true,
'filterable_in_search' => true,
'visible_in_advanced_search' => true,
'comparable' => false,
'visible_on_front' => false,
'used_in_product_listing' => true,
'unique' => false
]
);
And the block for input renderer is below:
<?php
namespace Velanapps\Test\Block\Adminhtml\Form\Element;
use Magento\Framework\Data\Form\Element\Date;
class DateTime extends Date {
public function getElementHtml() {
$this->setDateFormat($this->localeDate->getDateFormat(\IntlDateFormatter::SHORT));
$this->setTimeFormat($this->localeDate->getTimeFormat(\IntlDateFormatter::SHORT));
return parent::getElementHtml();
}
}
But is only show date. Please let me know if anybody has created with time already.. Thanks in advance...