I'm trying to enter the date in tags default_items.php (in an override) to see the date in tags list.

I am using <?php echo $item->displayDate; ?> and this prints: 2018-08-04 06:04:37, but I'm trying to format the date as 4 Aug 2018.

I tried the code below to change the format and display:

$mydate = $item->displayDate;
echo $mydate->format('j M Y');

but this generates an error:

Call to a member function format() on string

How can I change the date to the new format?


1 Answer 1


$mydate = $item->displayDate; simply refers to the date string, therefore $mydate is not an object and you cannot format() it.

You'll need to pass the date string through JHtmlDate like so:

echo JHtml::_('date', $item->displayDate, 'j M Y');

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