2

This question already has an answer here:

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:

<?php
$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?

marked as duplicate by mickmackusa, Community Sep 30 '18 at 5:10

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2

$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.