Format Date In Joomla

In this tutorial I will teach you how to format the date. The date can be from an article, an extension or even the current date. I am using the published date for articles in the following examples.
Joomla provides a very useful function with some constants that you can use or provide your own.

In the first example we provide our own date format as the third parameter

Example 1.

$formatted_date = JHtml::_('date', $this->item->publish_up, JText::_('F d, Y'))); 
echo $formatted_date;

Result: April 20, 2016

The second example we use one of Joomla provided constants to format the date

Example 2.

$formatted_date = JHtml::_('date', $this->item->publish_up, JText::_(DATE_FORMAT_LC3))); 
echo $formatted_date;

Result: 20 April 2016

Below are Joomla date format constants

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

That’s it. Hopefully this helps with your Joomla coding.

Please Post Your Comments & Reviews

Welcome to Western Studios

We provide professional website and mobile softwares including Joomla, Wordpress and more.