Dima SubZero
Dima SubZero

Reputation: 33

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.

Thanks.

Upvotes: 1

Views: 12798

Answers (4)

user7085433
user7085433

Reputation:

when creating a custom attribute you just need to add

'input'=> 'datetime' instead of 'input'=> 'date'

Upvotes: 0

Milos
Milos

Reputation: 677

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
 ));

Upvotes: 4

Vishal
Vishal

Reputation: 900

Hello check app/code/local/Magik/Popup/Block/Adminhtml/Popup/Edit/Tab/Form.php

Add below code

$dateFormatIso=Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT);  
    $fieldset->addField("text_name", "date", array(
    "name"   => "text_name",
    "label"  => Mage::helper("modelname")->__("Start Date"),
    "title"  => Mage::helper("modelname")->__("Start Date"),
    "image"  => $this->getSkinUrl('images/grid-cal.gif'),
    "input_format" => Varien_Date::DATE_INTERNAL_FORMAT,
    "format"       => $dateFormatIso,
     "time" => false,
    "value" => "textstart", 
    ));

Upvotes: 0

Nikhil_K_R
Nikhil_K_R

Reputation: 2373

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.

Upvotes: 8

Related Questions