Show updated product date in Magento

I want to show the date of the last update (not the creation date) on the Magento product page.

<?php echo $_product->getUpdatedAt();?> IS WORKING

But I do not want to show TIME - only DATE.

Is it possible?

+4
source share
2 answers

Ashley solution should work, but first you have to wrap it strtotime()

echo date("Y-m-d", strtotime($_product->getUpdatedAt()));

I would recommend using the Magento date model to get the time in your time zone (it will also take care of your timestamp).

echo Mage::getModel('core/date')->date("Y-m-d", $_product->getUpdatedAt());

Take a look at app/code/core/Mage/Core/Model/Date.php

<?php

class Mage_Core_Model_Date
{
    /**
     * Converts input date into date with timezone offset
     * Input date must be in GMT timezone
     *
     * @param  string $format
     * @param  int|string $input date in GMT timezone
     * @return string
     */
    public function date($format = null, $input = null)
    {
        if (is_null($format)) {
            $format = 'Y-m-d H:i:s';
        }

        $result = date($format, $this->timestamp($input));
        return $result;
    }

    /**
     * Converts input date into timestamp with timezone offset
     * Input date must be in GMT timezone
     *
     * @param  int|string $input date in GMT timezone
     * @return int
     */
    public function timestamp($input = null)
    {
        if (is_null($input)) {
            $result = $this->gmtTimestamp();
        } else if (is_numeric($input)) {
            $result = $input;
        } else {
            $result = strtotime($input);
        }

        $date      = Mage::app()->getLocale()->date($result);
        $timestamp = $date->get(Zend_Date::TIMESTAMP) + $date->get(Zend_Date::TIMEZONE_SECS);

        unset($date);
        return $timestamp;
    }
}
+6
source

Magento saves the updatedAt attribute as the mysql timestamp. You should use normal PHP date functions to only show the date.

eg.

echo date("Y-m-d", $_product->getUpdatedAt());

magento, PHP, , , PHP.

-1

Source: https://habr.com/ru/post/1533187/


All Articles