I use a plugin that shows me list of posts and I want to change format of date. This is show me date like this:

24 january 2015 12:20:11 and this is the code of above output:

<?php echo $post->getCreatedTime(); ?>

But I want to show date like this:

24 january 2015

I use this code but this is show time in wrong month and date, for example instead of 24 january 2015 it shows me: Oct 12, 2015 !!!

<?php $_ct= new Zend_Date($post->getCreatedTime()); echo $_ct->toString('MMM dd, yyyy'); ?>

I don't have any idea why this is happen!!!

How can I fix it?

6 Answers 6


Don't forget about locale! As all other examples can cause issues for people from different time zones.


inside date() you can put any date and call method ->toString() with some param.

Pattern examples you can find in Varien_Date

const DATETIME_INTERNAL_FORMAT = 'yyyy-MM-dd HH:mm:ss';
const DATE_INTERNAL_FORMAT = 'yyyy-MM-dd';

const DATETIME_PHP_FORMAT       = 'Y-m-d H:i:s';
const DATE_PHP_FORMAT           = 'Y-m-d';

or use any you like.

For example for current time full call will look like this:


Use strtotime() function. See updated code below.

$_ct= new Zend_Date(strtotime($post->getCreatedTime()));
echo $_ct->toString('MMM dd, yyyy');    // will output Jan 24, 2015
  • When I use your code my page messed up and all data remove from page.
    – Elham Gdz
    Commented Aug 10, 2015 at 6:58
  • just wrap the parameter in Zend_Date function with strtotime()
    – Sukeshini
    Commented Aug 10, 2015 at 7:02
  • How can I do it? I am new in magento, please explain me more, thanks.
    – Elham Gdz
    Commented Aug 10, 2015 at 7:05
  • just change this line and check $_ct= new Zend_Date(strtotime($post->getCreatedTime()));
    – Sukeshini
    Commented Aug 10, 2015 at 7:07
  • When I just use <?php $_ct= new Zend_Date(strtotime($post->getCreatedTime())); ?> all data of my page will remove again!!!
    – Elham Gdz
    Commented Aug 10, 2015 at 7:12

I have use today this format which is working fine.

$createdtime = new Zend_Date(strtotime($post->getCreatedTime()));
echo Mage::getModel('core/date')->date('M d, Y', $createdtime);

Use something like this:

$date = $post->getCreatedTime();
$dateToShow = date('j F Y',strtotime($date));
echo $dateToShow;

About the exact format just use: http://php.net/manual/en/function.date.php

  • Your code show me this date: 1 January 1970 instead of 24 january 2015!!!
    – Elham Gdz
    Commented Aug 10, 2015 at 7:04
  • I m using the same.Either you did something wrong with the copy paste or the $date is null
    – vbak
    Commented Aug 10, 2015 at 7:17
  • No, I copy your code properly and $date isn't null because I created post that the date of each post show properly in admin panel.
    – Elham Gdz
    Commented Aug 10, 2015 at 7:21

Just you need to set your local time zone. so it's get your server time and print as you wish.


set your time zone. check if any problem tell me.

Happy Codding . :)


Please try below code

$anyDate = '24 january 2015 12:20:11';
echo $currentDate = Mage::getModel('core/date')->date('d F Y', $anyDate);

Your Answer

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

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