Add a date picker to system.xml on custom module

Add a date picker to system.xml on custom module

July 30, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Add a date picker to system.xml on custom module

Add a Date Picker Field to System.xml for Custom Magento Module

As an experienced Magento developer, I often encounter requests to add custom fields to the admin’s system configuration area using system.xml. One common requirement is adding a date field with its corresponding date picker. Let me guide you through this process step-by-step.

Understanding the Problem

In your case, you’re trying to extend the existing system.xml file for a custom module located at app/code/local/Namespace/Module/etc/system.xml. You want to add a new field that includes a date input field and automatically generates a date picker when accessed in the admin panel.

Analyzing the Given Code

You’ve tried to create a custom block called Datefield.php that extends Mage_Adminhtml_Block_System_Config_Form_Field. Inside the _getElementHtml() method, you’re calling Varien_Data_Form_Element_Abstract, but you’re unsure if it should be replaced with Varien_Data_Form_Element_Date.

The Correct Approach

To add a date field to your system.xml configuration, follow these steps:

  1. Create the Date Picker Method

First, you need to create a method inside your custom module’s config file (usually located at app/code/local/Namespace/Module/Model/System/Config.php).

class Namespace_Module_Model_System_Config extends Mage_Core_Model_Config_Backend_System {
    public function getDateFieldHtml($field, $value){
        return '<input type="text" name="'.$field.'" id="'.$this->getElementId($field).'" value="'.$value.'" class="input-text admin__field-control" data-ui-id="field-'.$field.'-control">';
    }
}
  1. Update the system.xml File

Next, add your new field inside the <fields> section of your existing system.xml file.

<fields>
    <my_date_field translate="label">
        <label>Choose date</label>
        <frontend_type>datefield</frontend_type>
        <backend_model>Namespace_Module_Model_System_Config</backend_model>
        <sort_order>10</sort_order>
    </my_date_field>
</fields>
  1. Create the Date Field Block

Finally, you need to create a new block that will handle rendering the date field. In your case, this would be Namespace_Module_Block_Datefield.php.

class Namespace_Module_Block_Datefield extends Mage_Adminhtml_Block_System_Config_Form_Field {
    protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element) {
        return '<input type="text" name="'.$this->getElement()->getName().'" id="'.$this->getElement()->getId().'" value="'.$this->htmlEscape($this->getElement()->getValue()).'" class="input-text admin__field-control" data-ui-id="field-'.$this->getElement()->getName().'-control">';
    }
}

Conclusion

To add a date field with a built-in date picker to your custom Magento module’s system.xml configuration, you need to follow these key steps:

  1. Create the DateField.php method inside app/code/local/Namespace/Module/Model/System/Config.php.

  2. Update your existing system.xml file to include the new field.

  3. Create a new block called Namespace_Module_Block_Datefield.php that extends Mage_Adminhtml_Block_System_Config_Form_Field.

  4. Ensure you have the proper dependencies and namespaces set up in your module’s config file (app/code/local/Namespace/Module/etc/config.xml).

Remember to clear your cache after making these changes.

For more detailed guides on Magento configuration, check out our series on system.xml customization at LaravelCompany.

Happy developing!

Extensions Admin Configuration Errors

Our network