0

I have added the date field in the custom form using below code :

// Added start date field
        $fieldset->addField('start_date', 'date', array(
            'label' => Mage::helper('slider')->__('Start Date'),
            'required' => false,
            'class' => 'validate-date validate-date-range date-range-attribute-from',
            'name' => 'start_date',
            'image' => $this->getSkinUrl('images/grid-cal.gif'),
            'input_format' => Varien_Date::DATE_INTERNAL_FORMAT,
            'format' =>  Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT),
            'time' => true
            ));

        // Added end date field
        $fieldset->addField('end_date', 'date', array(
            'label' => Mage::helper('slider')->__('End Date'),
            'required' => false,
            'class' => 'validate-date validate-date-range date-range-attribute-to',
            'name' => 'end_date',
            'image' => $this->getSkinUrl('images/grid-cal.gif'),
            'input_format' => Varien_Date::DATE_INTERNAL_FORMAT,
            'format' =>  Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT),
            'time' => true
            ));

And use below code to add date fields in data array at the time of saving

$data = $this->_filterDateTime($data, array('start_date', 'end_date'));

Now suppose I am choosing 09/30/2016 08:08 AM as end date
After saving the form, Magento is showing 9/30/2016 12:00 AM in the field.
Whereas in the database table the end_date entry is correct i.e. 2016-09-30 08:08:00

What can be the issue here and how it can be fixed?
Any help would be appreciated.

2 Answers 2

0

change below format setting and let me know its work or not, after that you can set default value for this or fetch from the db for that you can create a function like below

$default_date = "";  
if($this->getMyData()){
      $data = $this->getMyData();
      $default_date = $data['end_date'];
}
$fieldset->addField('end_date', 'date', array(
        'label' => Mage::helper('slider')->__('End Date'),
        'required' => false,
        'class' => 'validate-date validate-date-range date-range-attribute-to',
        'name' => 'end_date',
        'image' => $this->getSkinUrl('images/grid-cal.gif'),
        'input_format' => Varien_Date::DATE_INTERNAL_FORMAT,
        'format' =>  Mage::app()->getLocale()->getDateTimeFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT),
        'time' => true,
        'value' => $default_date
        ));

and function will be like below

protected function getMyData(){
    $id = $this->getRequest()->getParam('id');
    if($id){
        $data = Mage::getModel('yourmodule/yourmodule')->load($id);
        return $data->getData();
    }
    return FALSE;
}
2
  • Didn't work, using this, even date is changed to default date. Commented Sep 3, 2016 at 5:13
  • Have you seen My updated answer?? Commented Sep 3, 2016 at 6:42
0

Removing the 'input_format' from the date field worked for me.
I am sure what is the reason, if somebody can explain it that will be great.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.