0

I would like to display when a product was last modified on the backend of a item page. How could I do this?

0
  • To get Product updated time, from item page(Supposed it should be product page), try:
$product->getUpdatedAt()
  • To format the date you could inherit a function to a extended block or call in a helper.
/**
     * Retrieve formatting date
     *
     * @param null|string|\DateTimeInterface $date
     * @param int $format
     * @param bool $showTime
     * @param null|string $timezone
     * @return string
     */
    public function formatDate(
        $date = null,
        $format = \IntlDateFormatter::SHORT,
        $showTime = false,
        $timezone = null
    ) {
        $date = $date instanceof \DateTimeInterface ? $date : new \DateTime($date);
        return $this->_localeDate->formatDateTime(
            $date,
            $format,
            $showTime ? $format : \IntlDateFormatter::NONE,
            null,
            $timezone
        );
    }
<?= /* @escapeNotVerified */ $block->formatDate($product->getUpdatedAt()) ?>
<?= /* @escapeNotVerified */ $this->helper('Vendor\Module\Helper\Data')->formatDate($product->getUpdatedAt()) ?>
  • I have never done anything in the adminhtml area before. I tried to place the file in Magento_Theme/view/adminhtml/templates/title.phtml. I was thinking next to the header I could just add the date next to the title. It isn't pulling the correct template. What would you suggest? – tjjen Mar 5 at 18:41

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.