B-219 Sec-55 Noida, India

Magento date time

Are you using date-time functions (date(), time(),now(), etc) directly inside magento ??? Think twice man !!!

Even though time is set properly in you server or you set right timezone in your php.ini file, you might be surprised to see the result of the following code :-

//This time will not match your server time
$now = time();
echo date(‘m/d/y h:i:s’, time());

This is because whatever settings you have in your php.ini, Magento reset timezone to ‘UTC’ in Mage_Core_Model_App.

File:- appcodecoreMageCoreModelApp.php Line:-255


So, solution is set your targeted timezone in Admin->System->Configuration / General->Locale options and rather using date() function user the following code:-

$now = Mage::getModel(‘core/date’)->timestamp(time());
echo date(‘m/d/y h:i:s’, $now);

That’s it, have happy time with Magento 🙂 .

(Visited 65 times, 1 visits today)

Leave a reply

You must be logged in to post a comment.