So I have this component (built with JCB) where I need to display a saved datetime from the db (without seconds, but that's not my focus right now). Because of some limitations, I cannot simply declare use statements at the top of the model.

I'm now at the point that I called the JDate like so:

$date = new Joomla\CMS\Date\Date($item->kickoff);
$datenow = new JDate($item->kickoff);
$dateHtml =  '';
echo '<pre>' . var_export($item->kickoff,true) . '</pre>';
echo '<pre>' . var_export($date,true) . '</pre>';
$item->calculated_name =  $dateHtml;

The export gives me:

'2020-07-30 12:00:00'

   'tz' => DateTimeZone::__set_state(array(
       'timezone_type' => 2,
       'timezone' => 'GMT',
   'date' => '2020-07-30 12:00:00.000000',
   'timezone_type' => 2,
   'timezone' => 'GMT',

I should now be able to use the information from the export, but I cannot. I cannot access $date->date or $date->get('date') because it's in set state.

I'm not able to use HtmlHelper because I cannot use it like so:

$dateHtml = new Joomla\CMS\HTML\HTMLHelper($date, Text::_('DATE_FORMAT_FILTER_DATETIME'));

My goal: Access the kickoff date calculated with the offset (Joomla installation timezone)

Any hints?

1 Answer 1


Joomla\CMS\Date\Date doesn't have $date property or get() method. Use $date->format($format) to format the date where $format is the date format.

To format a date using Joomla\CMS\HTML\HTMLHelper, call its underscore method with date as first argument, followed by date and format:

Joomla\CMS\HTML\HTMLHelper::_('date', $item->kickoff, $format);

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.