How add time to datepicker in backend magento

12,448

Solution 1

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.

Solution 2

Try these (works on Magento 1.8):

   $this->addAttribute(Mage_Catalog_Model_Product::ENTITY, 'test_date_time', array(
     'input'         => 'datetime',
     'type'          => 'datetime',
     'time'          => true,
     'label'         => 'Date&Time',
     'visible'       => true,
     'required'      => false,
     'user_defined'  => true,
     'visible_on_front' => true,
     'backend'       => 'eav/entity_attribute_backend_time_created',
     'global'        => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_GLOBAL
 ));
Share:
12,448
Dima SubZero
Author by

Dima SubZero

Updated on November 23, 2022

Comments

  • Dima SubZero
    Dima SubZero over 1 year

    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.

    Thanks.

    • Nikhil_K_R
      Nikhil_K_R over 11 years
      reason 4 using mysql-setup file ?
  • Phil Birnie
    Phil Birnie over 9 years
    Thanks for the helpful start. This is works if you want it to automatically insert the current time into the field; I didn't so I created my own module with a backend model that extends eav/entity_attribute_backend_time_created -- this seems to work well.