Changing the date format in osCommerce

This post is an old post from my previous blog but I thought it might be still useful to some people so I'll repost it here rather than deleting it.

To change the date format used in osCommerce (when members create their account) from mm/dd/yyyy to dd/mm/yyyy, you simply need to change the main language file. The file should be located at catalog/includes/languages/<language_name>.php (for example: catalog/includes/languages/english.php).

I found the solution at the osCommerce forums in this thread, but it is missing a couple of things that were overlooked.

Change the file from (around line 21):

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');

////
// Return date in raw format
// $date should be in format mm/dd/yyyy
// raw date is in format YYYYMMDD, or DDMMYYYY
function tep_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);
  }
}

To:


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 strftime()
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');

////
// Return date in raw format
// $date should be in format mm/dd/yyyy
// raw date is in format YYYYMMDD, or DDMMYYYY
function tep_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);
}
}

You should also change (on about line 61):

From

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

To

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

The other change you need to make is on lines 175 and 176.

From:

define('ENTRY_DATE_OF_BIRTH_ERROR', 'Your Date of Birth must be in this format: MM/DD/YYYY (eg 05/21/1970)');
define('ENTRY_DATE_OF_BIRTH_TEXT', '* (eg. 05/21/1970)');

To:

define('ENTRY_DATE_OF_BIRTH_ERROR', 'Your Date of Birth must be in this format: DD/MM/YYYY (eg 21/05/1970)');
define('ENTRY_DATE_OF_BIRTH_TEXT', '* (eg. 21/05/1970)');

Thats about it...

Comments

Nice Article,
It Help Me.

There is one addition :: You need to do all same changes in administration side language file too. (for example: catalog/admin/includes/languages/english.php)

Thanks
J

Thanks for not deleting the date format page for oscommerce! Superstar!

hey,
thanks for the helpful tip, its helping in the new store :-)
i was searching for it and you came the first in results.

Thank You! I knew that the OSC thread was missing something. "return substr($date, 0, 2) . substr($date, 3, 2) . substr($date, 6, 4);" Especially when customers are complaining they can't put their birth date in.

MANY THANKS!

Thanks heaps for the article, learning OSCommerce in a hurry doesn't help, but this just made the learning experience just that little bit easier.

Cheers!

Great post saved me lots of time. Thanks.