How to add a date/time product attribute to Magento admin

Adding a date attribute to Magento is no problem – but what about date + time? In this article I’ll explain how to add a date/time product attribute to Magento admin programmatically with upgrade script. Basically to make it happen you need to configure the renderer for date field and source model to convert the date and save time as well as date.

So let’s start with renderer itself:

app/code/local/Youcompany/Yourmodule/Block/Adminhtml/Renderer/Datetime.php

Next – let’s create a source model that will handle this attribute on save:

app/code/local/Youcompany/Yourmodule/Model/Attribute/Datetime.php

And finally the upgrade script to create an attribute and connect it to model and renderer:

app/code/local/Youcompany/Yourmodule/sql/yourmodule_setup/mysql4-upgrade-0.0.1-0.0.2.php

You can use any setup options for you attribute, but the most important part here is:

and That’s it folks. Hope that helps.

Rating:

How to add a date/time product attribute to Magento admin
4.8 (95%) 4 vote[s]

Comments (6)

  1. I added the as described, but the datepicker still rest the same with only the date…
    I use magento 1.8.0.0

    • Do you see your custom attribute in attribute set? Just to make it clear – this will not change every datepicker in admin to display time – this will work only for the brand new added attribute.

  2. Hello,
    I added the as described, but i’ve got an error :
    Fatal error: Class ‘Mage_MyCompagny_MyModule_Checkout_Block_Adminhtml_Renderer_Datetime’ not found in …\lib\Varien\Data\Form\Abstract.php on line 144
    An Idea ?
    I use magento 1.11.1.0

  3. Hey Igor,

    I’m looking to change the default special date from and to, to include the time option too. Any idea how to do that?

    Cheers

What do you think?

Required fields are marked *


*