Date Format

From Zen Cart(tm) Wiki
Jump to: navigation, search

To change the date format from the default month/day/year, you need to make changes to includes/languages/<current language>.php.

Note: You will also have to do similar changes to admin/includes/languages/<current language>.php as mentioned on this page.

As always when changing core files, you're highly advised to make use of the override system.

Copy includes/languages/<current language>.php to includes/languages/<current template>/<current language>.php and open the new file.

First, edit the following section:

@setlocale(LC_TIME, 'en_US.ISO_8859-1');
define('DATE_FORMAT_SHORT', '%m/%d/%Y');  // this is used for strftime()
define('DATE_FORMAT_LONG', '%A %d %B, %Y'); // this is used for strftime()
define('DATE_FORMAT', 'm/d/Y'); // this is used for date()

See the PHP manual entries for strftime() and date() to learn about formatting.

setlocale() can be trickier to set correctly because it depends on the servers operating system.
If you're running on a Windows platform, see Language Strings or Country/Region Strings from the MSDN site.
If you're running on a *nix system, see the directory /usr/share/locale/ and try one of the directory names that match your language for setlocale(). If you can't access this directory, ask your host about what locales they have installed for your language.

Another way is to try to run the following PHP script (you might be restricted on the use of the system command, though):

echo "<hr><br>The available 'locale' strings for 'fr' on this server are:<br>";
echo '<pre>';
system('locale -a | grep -i fr');
echo '</pre>';

Of course, change 'fr' with es, it, or whatever country symbol you need.

If you don't set setlocale() correctly, you won't have localised settings such as month names, but the default US english instead.

You also need to replace the function zen_date_raw() - here's how it should look like to display date formats as day/month/year:

// $date is given in format mm/dd/yyyy
// raw date is in format YYYYMMDD, or DDMMYYYY
function zen_date_raw($date, $reverse = false) {
  if ($reverse) {
    return substr($date, 0, 2) . substr($date, 3, 2) . substr($date, 6, 4);
  } else {
    return substr($date, 6, 4) . substr($date, 3, 2) . substr($date, 0, 2);

To display date formats as year/month/day, the function should look like this:

// $date is given in format mm/dd/yyyy
// raw date is in format YYYYMMDD, or DDMMYYYY
function zen_date_raw($date, $reverse = false) {
  if ($reverse) {
    return substr($date, 8, 2) . substr($date, 5, 2) . substr($date, 0, 4);
  } else {
    return substr($date, 0, 4) . substr($date, 5, 2) . substr($date, 8, 2);

You'll also want to edit some text definitions. Do a search for DOB and DATE_OF_BIRTH in the following files and see what needs to be changed:

includes/languages/<current language>.php
admin/includes/languages/<current language>.php

Idea.png Tip!
If you want a more advanced function which can deal with more flexible formats such as optional month names instead of digits, see this user-submitted suggestion.