5

I would like to change the backend Joomla 3.0 date format for a custom component. Right now the component is taking the Joomla date backend format which is Y-m-d and that I need to change to d-m-Y for the custom component. I couldn't find where to change that format.

But one thing I found that the component date format code is coming from the following code:

<?php echo $item->date; ?>

And I would like to show the date in the following format:

echo date_format($date, 'd-m-Y H:i:s');

But don't know how I am going to implement it with the Joomla code. Need an idea on this.

3 Answers 3

8

You can set the date using JHtml as shown below:

<?php echo JHtml::_('date', $item->date, 'd-m-Y H:i:s'); ?>

So all you need to do is replace <?php echo $item->date; ?> with the above code

0
2

You can use pre formated strings and change in language files ex.: /language/en-GB/en-GB.ini

DATE_FORMAT_LC="l, d F Y"

DATE_FORMAT_LC1="l, d F Y"

DATE_FORMAT_LC2="l, d F Y H:i"

DATE_FORMAT_LC3="d F Y"

DATE_FORMAT_LC4="d.m.y"

DATE_FORMAT_JS1="d-m-y"

1
  • I love you more than you know.
    – Eoin
    Jul 17, 2020 at 21:12
0

For the purpose of J4 versions, I thought this may be of assistance to others.

use \Joomla\CMS\HTML\HTMLHelper;
use \Joomla\CMS\Language\Text;

echo HtmlHelper::date($date, Text::_('DATE_FORMAT_LC2'));

Your Answer

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

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