0

I am trying to add a datetime custom product attribute but it is showing date only I want to show time as well: enter image description here

Here is my install script:

<?php
namespace Custom\ProductScheduler\Setup;

use Magento\Eav\Setup\EavSetup; use Magento\Eav\Setup\EavSetupFactory; use Magento\Framework\Setup\InstallDataInterface; use Magento\Framework\Setup\ModuleContextInterface; use Magento\Framework\Setup\ModuleDataSetupInterface;

class InstallData implements InstallDataInterface { private $eavSetupFactory;

public function __construct(EavSetupFactory $eavSetupFactory)
{
    $this-&gt;eavSetupFactory = $eavSetupFactory;
}

public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
    $eavSetup = $this-&gt;eavSetupFactory-&gt;create(['setup' =&gt; $setup]);
    $eavSetup-&gt;addAttribute(
        \Magento\Catalog\Model\Product::ENTITY,
        'schedule_end',
        [
            'group' =&gt; 'Custom Product Scheduler',
            'label' =&gt; 'Schedule End Time',
            'type' =&gt; 'datetime',
            'input' =&gt; 'date',
            'class' =&gt; 'validate-date',
            'backend' =&gt; 'Custom\ProductScheduler\Model\Entity\Attribute\Backend\Datetime',
            'required' =&gt; false,
            'global' =&gt; \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
            'visible' =&gt; true,
            'user_defined' =&gt; true,
            'default' =&gt; '',
            'searchable' =&gt; true,
            'filterable' =&gt; true,
            'filterable_in_search' =&gt; true,
            'visible_in_advanced_search' =&gt; true,
            'comparable' =&gt; false,
            'visible_on_front' =&gt; true,
            'used_in_product_listing' =&gt; true,
            'unique' =&gt; false
        ]
    );
    $eavSetup-&gt;addAttribute(
        \Magento\Catalog\Model\Product::ENTITY,
        'schedule_status',
        [
            'group' =&gt; 'Custom Product Scheduler',
            'type' =&gt; 'int',
            'backend' =&gt; '',
            'frontend' =&gt; '',
            'label' =&gt; 'Schedule End Status',
            'input' =&gt; 'boolean',
            'class' =&gt; '',
            'source' =&gt; \Magento\Eav\Model\Entity\Attribute\Source\Boolean::class,
            'global' =&gt; \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_GLOBAL,
            'visible' =&gt; false,
            'required' =&gt; false,
            'user_defined' =&gt; true,
            'default' =&gt; '1',
            'searchable' =&gt; true,
            'filterable' =&gt; true,
            'comparable' =&gt; false,
            'visible_on_front' =&gt; true,
            'used_in_product_listing' =&gt; true,
            'unique' =&gt; false,
            'apply_to' =&gt; 'simple'
        ]
    );
}

}

Any help would be appreciated.

mechanic
  • 440
  • 5
  • 24

1 Answers1

0

You can use the modifiers to render the time with Date. Please use the reference

Magento 2 Create Date with Time attribute for product

Hope it works well thanks!!

Mohd Shahbaz
  • 579
  • 3
  • 7