How to Modify the Date Displayed on K2 Content Items

One of our Spanish-speaking customers needed to hide the hour and minutes displayed by K2 items.

By default, Joomla content doesn't display the time. So the customer wanted their K2 dates to match the normal Joomla articles on their site.

In this tutorial, you will learn to use a language override to achieve this.

 The image below shows the default view for K2 items in Spanish:

date by default

This next image shows the dates of K2 individual items:

date for item by default

Our customer wanted their dates without the hour and minutes:

no hours and minutes

The date format is set by this line: K2_DATE_FORMAT_LC2="l, d F Y H:i"

You'll find this language string in the /administrator/language/es-ES/es-ES.com_k2.dates.ini file. 

language string

Yes, you can edit this string and change it from K2_DATE_FORMAT_LC2="l, d F Y H:i" to K2_DATE_FORMAT_LC2="l, d F Y".

However, editing the file in not an ideal solution. Joomla constantly updates. International language packages get updated as well. If you apply the date fix editing the /administrator/language/es-ES/es-ES.com_k2.dates.ini file directly, you will lose it next time you install a newly released K2 language pack. There is a way to avoid this future problem.

  • In your Joomla backend, go to Extensions > Language(s) > Overrides:

extensions language overrides

  • You will be taken to the Languages: Overrides administrative page.
  • Click New:

click new

  • Next, switch the Search For box from Value to Constant:

from value to constant 

  1. Enter  K2_DATE_FORMAT_LC2 into the Search box.
  2. Click Search:

enter the constant and click search

  1. Click on the first search result.
  2. You will see the date formatting code of %A, %d %B %Y %H:%M appeared inside the Text box:

click on the first search result notice the change

  1. Replace the %A, %d %B %Y %H:%M code with the l, d F Y.
  2. Click Save & Close:

replace and save

  • You will see your new language override listed:

new language override listed

There you have it. If you check how your K2 content gets displayed on your site front end, you will notice that the hour and minutes don't get displayed now.