3

I want to display invoice created date in invoice e-mail template. I am using {{var invoice.created_at}} to display invoice created date. But it displaying 2015-05-25 13:30:55 . I need to only display date as 25 JUL 2015. Please help me. Thanks in advance.

1

3 Answers 3

4

You can rewrite or copy the code from Mage/Sales/Model/Order/Invoice.php to local folder and add the below function

public function getInvoiceDate()
    {
        $createdAt = $this->getCreatedAt();
        $invoiceDate = date('d M Y', strtotime($createdAt));
        return $invoiceDate;
    }

In invoice email template, get the date as {{var invoice.getInvoiceDate()}}. Like this you can add any number of functions and get from email templates

0
1

Please note that in addition to Adarsh' answer, the getCreatedAtFormated()-method is only applied to the Mage_Sales_Model_Order-object. So in order to make use if it in an invoice e-mail, you need to use:

{{var invoice.getOrder().getCreatedAtFormated('medium')}}

Unfortunately this will still show the time.

1
  • This is wrong. Not necessarily order and invoice have the same date. You cannot show the wrong data in the invoice. Commented Apr 11, 2021 at 23:55
0

For formatting date in email template use following line:

{{var order.created_at('medium')}}

See following function in /app/code/core/Mage/Sales/Model/Order.php

/**
 * Get formated order created date in store timezone
 *
 * @param   string $format date format type (short|medium|long|full)
 * @return  string
 */
public function getCreatedAtFormated($format)
{
    return Mage::helper('core')->formatDate($this->getCreatedAtStoreDate(), $format, true);
}

Hope this helps.

UPDATE

Since there is no date formatting function written in invoice class, you can extend the Invoice and add below code:

/**
     * Get formated invoice created date in store timezone
     *
     * @param   string $format date format type (short|medium|long|full)
     * @return  string
     */
    public function getCreatedAtFormated($format)
    {
        return Mage::helper('core')->formatDate($this->getCreatedAt(), $format, true);
    }

Now, you can call in your transactional email:

{{var invoice.getCreatedAtFormated(medium)}}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.