Magento 1.9 – Admin Form Save Date Format Issue

adminformdatabasedatemagento-1.9

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.

Best Answer

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

Related Topic