Magento 1.9 Email Templates – Get Order Datetime Including Timezone in Email Template

email-templatesmagento-1.9order-emailtimezone

I try to modify default New Order email template.

Currently, I get order datetime by {{var order.getCreatedAtFormated('short')}}.
It results 6/18/2015 12:18 PM.

I want to include timezone following datetime, expected result is 6/18/2015 12:18 PM GMT+7.

I dive into Magento Core code to understand how it works, then I try

{{var order.getCreatedAtFormated('short')}} {{var order.getCreatedAtStoreDate().getTimezone()}}

but it doesn't work.

I know that if it works, getTimezone() may result Asisa/Saigon instead of GMT+7 as expected.

So, how to get order datetime including timezone?

Best Answer

There is no native function to get the GMT time value.

To get the GMT value of order created datatime.

I have rewrite the Mage_Sales_Model_Order and write new function to get the GMT.

(Refer magento model rewrite Tutorial)

public function getGmtValue()
{
    $timeZone = $this->getCreatedAtStoreDate()->getTimezone();
    $currentTimezone = date_default_timezone_get();
    date_default_timezone_set($timeZone);
    //Get GMT
    $value = date('P', strtotime($this->getCreatedAtStoreDate()));
    date_default_timezone_set($currentTimezone);
    return 'GMT'.$value;
}

Now you can get GMT value in email template by following code.

{{var order.getGmtValue()}}

I have refer these two links to get the GMT value

1.how do i get greenwich mean time in php

2.datetime to timestamp in php