11

I tried to create an attribute for product which has to be display date and time calender and that should be stored in database as date and time formate only.I struggled it for a lot but no luck.Can you please any one help me.. this is my script

$eavSetup->addAttribute(
        \Magento\Catalog\Model\Product::ENTITY,
        'xyz_start_time',
        [
        'group' => 'xyz',
        'type' => 'datetime',
        'backend' => '',
        'frontend' => '',
        'label' => 'Start Time',
        'input' => 'date',
        'class' => '',
        'source' => '',
        'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_GLOBAL,
        'visible' => true,
        'required' => false,
        'user_defined' => true,
        'default' => '',
        'searchable' => false,
        'filterable' => false,
        'comparable' => false,
        'visible_on_front' => false,
        'used_in_product_listing' => true,
        'unique' => false,
        'apply_to' => 'simple,configurable,virtual,bundle,downloadable'
        ]
        );

$eavSetup->addAttribute( \Magento\Catalog\Model\Product::ENTITY, 'xyz_end_time', [ 'group' => 'xyz', 'type' => 'datetime', 'backend' => '', 'frontend' => '', 'label' => 'End Time', 'input' => 'date', 'class' => '', 'source' => '', 'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_GLOBAL, 'visible' => true, 'required' => false, 'user_defined' => true, 'default' => '', 'searchable' => false, 'filterable' => false, 'comparable' => false, 'visible_on_front' => false, 'used_in_product_listing' => true, 'unique' => false, 'apply_to' => 'simple,configurable,virtual,bundle,downloadable' ] );


It is creating datepicker with date only not showing time on it.

3

2 Answers 2

2

One of the possible solutions is to use Modifiers. You would need to define a modifier in Vendor\Module\etc\adminhtml\di.xml and then create the modifier itself in Vendor\Module\Ui\DataProvider\Product\Form\Modifier\Datetime.php. The modifier should set time config for your attribute.

Please refer to this answer here for more info: Magento 2 Create Date with Time attribute for product

0

It is a bug with magento2. The field is actually a datetime, however the date picker is only date without time. As a quick workaround you can use the API to set a datetime. Or else you will need to override Magento's datepicker or file for a bug in github.

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.