Dima SubZero Dima SubZero - 1 year ago 72
PHP Question

How add time to datepicker in backend magento

I'am using magento 1.7.2 and I want to add date attribute with time which saves date as well as time in database for that product.

i had tried this code to add new attribute using mysql-setup file in my module.

$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,

but this gives me only date to select not time.

Please help me.


Answer Source

Try this for backend (any admin panel form):

$fieldset->addField('your_column_name', 'date',array(
          'name'      =>    'image_link', /* should match with your table column name where the data should be inserted */
          'time'      =>    true,
          'class'     => 'required-entry',
          'required'  => true,        
          'format'    =>    $this->escDates(),
          'label'     =>    Mage::helper('featuredpopup')->__('From:'),
          'image'     =>    $this->getSkinUrl('images/grid-cal.gif')

in format u can write directly 'yyyy-MM-dd HH:mm:ss' or one more method like

private function escDates() {
        return 'yyyy-MM-dd HH:mm:ss';   

Hopes this gives u an idea.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download