We load data from our supplier about the date when new stock will arrive. The date is loaded like: 07-12-2016, which is 12 July 2016 and not 7 December 2016.

I use following code to load the date:


<p class="availability out-of-stock"><?php $today = Mage::helper('core')->htmlEscape($_product->getData('delivery_eta')); $date = Mage::helper('core')->formatDate($today, Mage_Core_Model_Locale::FORMAT_TYPE_FULL, false); echo $date;?></p>

But this is displayed as 7 December 2016. How can I change this, so that the date is loaded correctly like 12 July 2016?

  • 07-12-2016 - this is 12 July, right? Please correct it in your post
    – Neklo.com
    Jul 6, 2016 at 8:44
  • @Neklo.com Sorry, you are right. I changed it.
    – JGeer
    Jul 6, 2016 at 8:45
  • The date shown without setting specific formatting will be formatted according to choosen locale. Change your locale to English (United States) and check the formatted date one more time. For example the date you've said is July isn't right in many countries in Europe. That's why you shouldn't override the locale-specific date for all stores if they're working on different languages.
    – versedi
    Jul 11, 2016 at 10:05

3 Answers 3


Here is new code.

$date = new Zend_Date($_product->getData('delivery_eta'), 'MM-dd-yyyy');
$date = Mage::helper('core')->formatDate(
    $date, Mage_Core_Model_Locale::FORMAT_TYPE_FULL, false
echo $date;
  • Thanks! I tried that, but that does display the date of today. Not the date of the delivery_eta attribute.
    – JGeer
    Jul 11, 2016 at 9:49
  • Am I missing something?
    – JGeer
    Jul 12, 2016 at 7:38
  • Sorry, don't see any error in code and it works well for me. Just maybe your delivery_eta data contain also time (hours, minutes, seconds)?
    – Neklo.com
    Jul 12, 2016 at 11:14
  • No, my date just looks like this: 07-12-2016. But in my case it is displaying the date of today, not thet date of the delivery_eta.. How is that possible?
    – JGeer
    Jul 12, 2016 at 14:20
  • Tried it again and I still get the date of today. How can I solve this?
    – JGeer
    Jul 14, 2016 at 11:40

You can just convert your data on the fly, like this

$dateString = $_product->getData('delivery_eta');
$myDateTime = DateTime::createFromFormat('m-d-Y', $dateString);
$newDateString = $myDateTime->format('d-m-Y');
$today = Mage::helper('core')->htmlEscape(newDateString);
$date = Mage::helper('core')->formatDate($today, Mage_Core_Model_Locale::FORMAT_TYPE_FULL, false); 

or, equivalently:

$dateString = $_product->getData('delivery_eta');
$newDateString = date_format(date_create_from_format('m-d-Y', $dateString), 'd-m-Y');
$today = Mage::helper('core')->htmlEscape(newDateString);
$date = Mage::helper('core')->formatDate($today, Mage_Core_Model_Locale::FORMAT_TYPE_FULL, false); 
  • Thanks! What will the best and fastest way? Equivalently?
    – JGeer
    Jul 6, 2016 at 8:57
  • first one is more correct from developer point of view
    – Neklo.com
    Jul 6, 2016 at 9:00
  • I tried your code, but that does not seem to work. I do not get any value.
    – JGeer
    Jul 6, 2016 at 15:23
  • oh, sorry, I've missed $ sign at line 4. It should be $today = Mage::helper('core')->htmlEscape($newDateString);
    – Neklo.com
    Jul 7, 2016 at 22:31
  • Thanks! I tried the new code, but that also does not work. The date is not displayed.
    – JGeer
    Jul 11, 2016 at 6:18

Try this

<p class="availability out-of-stock">
    $deliveryDate = $_product->getData('delivery_eta'); 
    $today = date('m-d-Y', strtotime($deliveryDate)); 
    $date = Mage::helper('core')->formatDate($today, Mage_Core_Model_Locale::FORMAT_TYPE_FULL, false);
<?php echo $date;?>
  • Thanks! I tried that code, but that does not work.
    – JGeer
    Jul 12, 2016 at 7:36

Your Answer

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

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