Loading
Cancel
Webmail Login
Control Panel Login
Zencart : Change date format to UK DD/MM/YYY
.CO.UK ONLY £5.33
Find your perfect domain here

Zencart : Change date format to UK DD/MM/YYY

How to change the zencart date to UK format

Whilst Zencart is a great e-commerce program, one issue we have a lot of users asking is how to change the date format to UK ( DD/MM/YYYY) instead of the US format (MM/DD/YYYY). In this brief tutorial we will show you which coding you need to change and also provide you with a download link with the files already edited.

1 : Locate and open your language file.

The first file you will need to edit is your language.php. This will either be located at

includes/languages/<YOUR_TEMPLATE>/<YOUR_LANGUAGE>.php

if you have a template installed or if not the default file will be at

includes/languages/<YOUR_LANGUAGE>.php (usually called english.php)

2 : Edit the following lines in english.php (or your-language.php)

Locate this section on line 22

@setlocale(LC_TIME, 'en_US');
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()
define('DATE_TIME_FORMAT', DATE_FORMAT_SHORT . ' %H:%M:%S');

and replace this with

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

Next in the same file scroll down and locate the below usually around line 29

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

and replace this with

// Return date in raw format
// $date should be in format mm/dd/yyyy
// raw date is in format YYYYMMDD, or DDMMYYYY
if (!function_exists('zen_date_raw')) {
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);
}
}
}

Near line 67 find

// text for date of birth example
  define('DOB_FORMAT_STRING', 'mm/dd/yyyy'); 

and again replace this with

// text for date of birth example
define('DOB_FORMAT_STRING', 'dd/mm/yyyy');

Around line 200 you should see

define('ENTRY_DATE_OF_BIRTH_ERROR', 'Is your birth date correct? Our system requires the date in this format: MM/DD/YYYY (eg 05/21/1970)');
define('ENTRY_DATE_OF_BIRTH_TEXT', '* (eg. 05/21/1970)');

change this to

define('ENTRY_DATE_OF_BIRTH_ERROR', 'Is your birth date correct? Our system requires the date in this format: DD/MM/YYYY (eg 21/05/1970)');
define('ENTRY_DATE_OF_BIRTH_TEXT', '* (eg. 21/05/1970)');

Once you have made all these changes you will need to save the file and re-upload it to your site.

2. Open file admin/includes/languages/<YOUR_LANGUAGE>.php

The next file you need to edit will be located at admin/includes/languages/<YOUR_LANGUAGE>.php. Again the default language file is english.php if you have added another language you will need to change this instead. Please also note that your Zencart admin directory shouldn't be called 'admin' as you should have renamed it for security reasons when installing Zencart.

Around line 20, find the following code

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()
define('PHP_DATE_TIME_FORMAT', 'm/d/Y H:i:s'); // this is used for date()
define('DATE_TIME_FORMAT', DATE_FORMAT_SHORT . ' %H:%M:%S');
define('DATE_FORMAT_SPIFFYCAL', 'MM/dd/yyyy'); //Use only 'dd', 'MM' and 'yyyy' here in any order

and replace this with

setlocale(LC_TIME, 'en_US.ISO_8859-1');
define('DATE_FORMAT_SHORT', '%d/%m/%Y'); // this is used for strftime()
define('DATE_FORMAT_LONG', '%A %d %B, %Y'); // this is used for strftime()
define('DATE_FORMAT', 'd/m/Y'); // this is used for date()
define('PHP_DATE_TIME_FORMAT', 'd/m/Y H:i:s'); // this is used for date()
define('DATE_TIME_FORMAT', DATE_FORMAT_SHORT . ' %H:%M:%S');
define('DATE_FORMAT_SPIFFYCAL', 'dd/MM/yyyy'); //Use only 'dd', 'MM' and 'yyyy' here in any order

Next around line 29, locate

// Return date in raw format
// $date should be 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, 3, 2) . substr($date, 0, 2) . substr($date, 6, 4);
} else {
return substr($date, 6, 4) . substr($date, 0, 2) . substr($date, 3, 2);
}
}

and change this to match the below.

// Return date in raw format
// $date should be 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);
}
}

Scroll down to around line 85 and find

// text for date of birth example
define('DOB_FORMAT_STRING', 'mm/dd/yyyy'); 

alter to

// text for date of birth example
define('DOB_FORMAT_STRING', 'dd/mm/yyyy');

Scroll down again and around line 204 find

define('JS_DOB', '* The \'Date of Birth\' entry must be in the format: xx/xx/xxxx (month/date/year).\n');

and change to

define('JS_DOB', '* The \'Date of Birth\' entry must be in the format: xx/xx/xxxx (date/month/year).\n');

Finally around line 231 the below

define('ENTRY_DATE_OF_BIRTH_ERROR', ' <span class="errorText">(eg. 05/21/1970)');</span>

and change this to

define('ENTRY_DATE_OF_BIRTH_ERROR', ' <span class="errorText">(eg. 21/05/1970)');</span>

Next save the file and re-upload it to your server.

That's it! If all the changes have been done correctly, your Zencart site should now use the UK time format instead of the US time format.

Download Zencart US date to UK date format plugin

The below download is a plugin we've created that should make all the changes above for you. Please note that the below download only works for sites using english.php. If your site uses any other language than English you will need to follow the above guide.

You will need to make some small changes to the download though;

1) If you have installed or are using any template other than the default template you will need to change the <YOUR TEMPLATE> folder to match the name of your template folder.

2) if you haven't installed a template then you will need to move the english.php file from

includes/languages/<YOUR_TEMPLATE>/

to

includes/languages/

and you can delete the <YOUR_TEMPLATE> folder

Download

You can download our Zencart US to UK date format plugin soon. Please check back later.



Leave a comment

Has this guide helped you? Have an idea for a guide or need help? Let us know below.

© Copyright 2014 | Squirrel Hosting Limited
Company Number 9031308