'Magento's formatDate helper prints incorrect date
In a Magento template, i am picking a Date which is stored as a product attribute. That's the config (setup ressource):
# Attribute default config - every property can be overridden
$defaultAttributeConfig = array(
'input' => 'date',
'type' => 'datetime',
'backend' => 'eav/entity_attribute_backend_datetime',
'frontend' => 'eav/entity_attribute_frontend_datetime',
'visible' => true,
'visible_on_front' => false,
'required' => false,
'user_defined' => false,
'used_in_product_listing' => true,
'group' => $defaultAttributeGroup,
'global' => Mage_Catalog_Model_Resource_Eav_Attribute::SCOPE_STORE,
'apply_to' => 'bundle,simple,configurable',
# Other
'default' => null,
'source' => null,
'searchable' => false,
'visible_in_advanced_search' => false,
'filterable' => false,
'filterable_in_search' => false,
'comparable' => false,
'is_html_allowed_on_front' => true,
'is_configurable' => false,
'used_for_sort_by' => false,
'position' => 0,
'used_for_promo_rules' => false,
);
$installer->addAttribute(
$productEntityTypeId,
'time_lapse_begin',
array_merge($defaultAttributeConfig, array(
'label' => 'Time-lapse begin',
'sort' => 10,
))
);
In my template file i am processing the date for debugging purposes as follows:
<?php list($timeLapseBegin, $timeLapseEnd) = array($_product->getTimeLapseBegin(), $_product->getTimeLapseEnd()); ?>
<?php if ($this->validateDate($timeLapseBegin)): ?>
<p>
Origin Date <?php echo $timeLapseBegin ?><br />
Full Date: <?php echo Mage::helper('core')->formatDate($timeLapseBegin, 'full'); ?><br />
Long Date: <?php echo Mage::helper('core')->formatDate($timeLapseBegin, 'long'); ?><br />
Medium Date: <?php echo Mage::helper('core')->formatDate($timeLapseBegin, 'medium'); ?><br />
Short Date: <?php echo Mage::helper('core')->formatDate($timeLapseBegin, 'short'); ?>
</p>
<?php endif; ?>
Unfortunately, the output isn't as expected:
Origin Date 2013-01-01 00:00:00
Full Date: Montag, 31. Dezember 2012
Long Date: 31. Dezember 2012
Medium Date: 31.12.2012
Short Date: 31.12.12
As you can see, the Origin Date reads 2013/01/01, but Magento's helper formats it to 2012/12/31 - this is a day before and not expected...
Any help or hint is appreciated. Thank you in advance!
Solution 1:[1]
Mage::app()->getLocale()->date($data['start_date'], Zend_Date::DATE_SHORT, null, false);
Set 'useTimezone' to False
See Magento custom module date field saving date to one day before the selected date
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Community |