Request Quote

How to add datetime type field to a custom form in Magento 2

In this blog we will learn how to add a datetime type field to a fieldset in custom form at admin side in Magento 2.

We will not explain here basic form creation. If you beginner then you can check this blog .

After successfully created basic form. Now you can add following code into Form.php In App/Code/Webkul/Grid/Block/Adminhtml/Grid/Edit to add datetime field.

$fieldset->addField(
    'start_date',
    'date',
    [
        'name' => 'start_date',
        'label' => __('Start Date'),
        'id' => 'start_date',
        'title' => __('Start Date'),
        'date_format' => 'yyyy-MM-dd',
        'time_format' => 'hh:mm:ss',
        'required' => true            
    ]
);

It will create a datetime type field like below in admin form,

 

Thanks for reading. Feel free to comment if you face any issue.

. . .

Comment

Add Your Comment

Be the first to comment.

css.php
Hire Us!
Brief us about your requirements and we'll get back to you.
Woo! Hooy!
We have just recieved your project brief and our expert will contact you shortly.
Send Again
Close