Search This Blog

Tuesday 20 November 2012

Working with date functions in Magento


The date time will be calculated based on the lacale timezone settings in administration:

    $anyDate = '2012-11-21 13:00:00';
    $dateTimestamp = Mage::getModel('core/date')->timestamp(strtotime($anyDate));
    echo $currentDate = date('Y-m-d H:i:s', $dateTimestamp);

Click here for more details




Other PHP scripts to find the offset for the timezone

/** Script to calculate the offset seconds fro the timezone */
$timezone = new DateTimeZone("Europe/London");
$offset = $timezone->getOffset(new DateTime("now")); // Offset in seconds
echo ($offset < 0 ? '-' : '+').round($offset/3600).'00'; // prints "+1100"

/** Script to convert the date and time to specific timezone */
$value = "2012-09-21 13:00:00";
$date = new DateTime($value);
$date->setTimezone(new DateTimeZone('Europe/London'));
echo $date->format('Y-m-d H:i:s');

No comments:

Post a Comment