How add time to datepicker in backend magento

How add time to datepicker in backend magento

July 6, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How add time to datepicker in backend magento

Adding Time to a Datepicker in Magento: A Comprehensive Guide

If you’re working on a Magento project and need to add a date attribute that includes time functionality, you’ve come to the right place. In this post, we’ll walk through the process of adding a new attribute with both date and time options using a custom module.

The Problem: Time Isn’t Showing Up in the Datepicker

You’ve already taken a commendable first step by trying to add a new date attribute via the mysql-setup file. Here’s your code:

$setup->addAttribute('catalog_product', 'new_date', array(
    'group' => 'General',
    'input' => 'date',
    'type' => 'datetime',
    'label' => 'New Date',
    'backend' => 'eav/entity_attribute_backend_datetime',
    'visible' => 1,
    'required' => 0,
    'user_defined' => 1,
    'searchable' => 1,
    'filterable' => 1,
    'comparable' => 1,
    'visible_on_front' => 1,
    'visible_in_advanced_search' => 0,
    'is_html_allowed_on_front' => 1,
    'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL,
));

The issue lies in the input field. Setting it to 'date' only allows you to select a date, not a time.

The Solution: Using the Correct Input Type

To include both date and time functionality, you need to use the date_time input type instead of date.

Here’s the corrected code:

$setup->addAttribute('catalog_product', 'new_date', array(
    'group' => 'General',
    'input' => 'date_time',
    'type' => 'datetime',
    // ... rest of your configuration ...
));

By changing 'input' => 'date' to 'input' => 'date_time', you’ll now see a datepicker that also allows you to select the time when editing or creating a product.

What About the Frontend Form?

You might wonder if this change will automatically update the frontend form. The answer is yes, but there’s an important caveat.

By default, Magento uses the core catalog_product_edit_form.xml layout file for the admin product edit page. This file is responsible for rendering the datepicker with time functionality.

However, since you’re creating a custom attribute via a setup script, Magento won’t automatically associate this new attribute with the existing date form element in the layout XML file.

To ensure the datepicker with time appears on the frontend product edit page, you’ll need to add your new attribute to the catalog_product_edit_form.xml layout by extending or overriding it within your module.

Conclusion

Adding a date and time attribute to Magento products is a straightforward process once you know the correct input type. Remember to use 'input' => 'date_time' for both the backend and frontend forms.

Don’t forget to properly test your setup script and any associated layout updates to ensure everything works as expected in your specific Magento installation.

If you found this guide helpful, I recommend exploring Laravel Company’s extensive Magento resources for more advanced topics such as module development, theme customization, and performance optimization.

Catalog Database Extensions Admin

Our network