Magento1.9 Product Date – Fix Created_at Date Format Changing

databasemagento-1.9MySQLproducts

Any time a product is updated and saved, its "created_at" entry in the "catalog_product_entity" database table is updated to the format YYYY-DD-MM, but it should keep it as YYYY-MM-DD. The date/time do not change, only the format. It isn't a big problem in itself, but it is creating problems when I attempt to sort products by creation date.

Here is an example:

  • created_at before: 2015-04-10 13:21:09 (YYYY-MM-DD)
  • edit and save product via Magento
  • created_at after: 2015-10-04 13:21:09 (YYYY-DD-MM)

Extra information: It is a Magento 1.9.1 store with the locale set to English (US) and timezone set to Los Angeles. The products from the store were originally imported via Magento's Import/Export feature from a wooCommerce store. Let me know if you need any more info.

Best Answer

you have to use

Mage::getModel('core/date')->gmtDate() 

instead of

$zendDate->getIso()

below is the solution.

open following file : app\code\core\Mage\Eav\Model\Entity\Attribute\Backend\Time\Created.php

and comment out beforeSave() function and replace with following function code.

  public function beforeSave($object)
{
    $attributeCode = $this->getAttribute()->getAttributeCode();

    $date = $object->getData($attributeCode);

    if (is_null($date)) {
        if ($object->isObjectNew()) {

            $object->setData($attributeCode, Varien_Date::now());
        }
    } else {
        // convert to UTC
        $zendDate = Mage::app()->getLocale()->utcDate(null, $date, true, $this->_getFormat($date));

        // Replace -> $zendDate->getIso() with Mage::getModel('core/date')->gmtDate()
        $object->setData($attributeCode, Mage::getModel('core/date')->gmtDate());
    }

    return $this;
}
Related Topic