I want to show the date of last update (not creation date) in a Magento product page.
<?php echo $_product->getUpdatedAt();?> IS WORKING
But I don't want to show the TIME — only the DATE.
Is that possible?
Ashley's solution should work, but you may have to wrap it in strtotime()
first
echo date("Y-m-d", strtotime($_product->getUpdatedAt()));
I would recommend using Magento's date model to get the time in your timezone (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;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With