4

I have created a new custom form/grid with a date field, I've also set up a table with the 'date' field to match.

$this->addColumn('date', array(
  'header'    => Mage::helper('ifactory_document')->__('Date'),
  'width'     => '150px',
  'index'     => 'date',
  'type'      => 'date',
  'format'    => Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT)
));

...

$fieldset->addField('date', 'date', array(
    'label' => 'Date',
    'required' => FALSE,
    'name' => 'date',
    'image' => $this->getSkinUrl('images/grid-cal.gif'),
    'format' => Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT),
    'value' => date( Mage::app()->getLocale()->getDateStrFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT))
));

The format in the grid & form is "d/MM/YYYY" and in the database it is in the format "YYYY/MM/d"

However before it is saved in the database it is converted to "MM/d/YYYY" format. If I save 4/5/2015 (4th of May) it will appear in database as 2015/4/5 (5th of April) any day values above 12 cause a failure.

I have tried inputting date directly into database and that has worked but saving still reproduces the issue. I have also checked configuration setting suggested in this post, as well as clearing magento cache but the issue still exists.

7

Found the problem, was missing a step in my controller.

$postData = $this->getRequest()->getPost();

$postData = $this->_filterDates($postData, array("date"));

After using _filterDates it started saving correctly

  • OMG, I was looking for this ..... for a very long time. THANK YOU THANK YOU THANK YOU!!!!! – Rob D. A. Feb 2 at 0:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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