1

I want to display only date from the below function.

$this->formatTime($item->getCreatedTime(), 'short', true);

This displays both date and time of creation something like:

3/21/2017 11:42 AM

I want only 3/21/2017

Sach
  • 83
  • 4
  • 24
  • 1
    Possible duplicate of [Convert one date format into another in PHP](http://stackoverflow.com/questions/2167916/convert-one-date-format-into-another-in-php) – Lukas Körfer Mar 21 '17 at 08:53

4 Answers4

0

Try this:

date('m/d/Y', strtotime($item->getCreatedTime()));
Mayank Pandeyz
  • 25,704
  • 4
  • 40
  • 59
0

You can try this

$date = $this->formatTime($item->getCreatedTime(), 'short', true);

$newdate = date('m/d/Y', strtotime($date));

echo $newdate; // Output : 3/21/2017
Chetan Panchal
  • 393
  • 2
  • 10
0

You can use date format

 echo date('m/d/Y', $this->formatTime($item->getCreatedTime(), 'short', true));
Nishant Nair
  • 1,999
  • 1
  • 13
  • 18
0

Answers by other users are not correct, using date will not take Magento's time zone configuration into account.

Instead following should be used:

Mage::getModel('core/date')->date('m/d/Y', $item->getCreatedTime());

Mladen Ilić
  • 1,667
  • 1
  • 17
  • 21
  • Yes, however using PHP's `date` function will lead to inaccurate dates due to Magento's timezone settings. This is why using Magento's `core/date` model should be used instead. :) – Mladen Ilić Mar 21 '17 at 11:52