Forums / General Questions / How do I change the Date format?

How do I change the Date format?

Locked

Views: 108,760

Results 1 to 20 of 69
This thread is locked. New replies are disabled.
4 Feb 2007, 11:53 AM
#1
tobicky avatar

tobicky

New Zenner

Join Date:
Feb 2007
Posts:
20
Plugin Contributions:
0

How do I change the Date format?

I wish to change the date from the default "US Format MM/DD/YYYY" to the "UK Format DD/MM/YYYY".

Is there an easy solution?

BR

Toby

6 Feb 2007, 3:45 AM
#2
bunyip avatar

bunyip

Totally Zenned

Join Date:
Sep 2004
Location:
Western Massachusetts
Posts:
2,361
Plugin Contributions:
1

Re: How do I change the Date format?

in your override copy of english.php, modify this 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()
  define('DATE_TIME_FORMAT', DATE_FORMAT_SHORT . ' %H:%M:%S');

Neville
An assumption is what you arrive at when you get tired of thinking...

6 Feb 2007, 9:47 PM
#3
tobicky avatar

tobicky

New Zenner

Join Date:
Feb 2007
Posts:
20
Plugin Contributions:
0

Re: How do I change the Date format?

Hi

I made the following changes to my english.php:

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

Is this everything?

When I go to the create account page on my site - it still says for "Date of Birth" the system requires the MM/DD/YYYY Format..

I hope you can help?

Kind Regards

Toby

6 Feb 2007, 11:27 PM
#4
bunyip avatar

bunyip

Totally Zenned

Join Date:
Sep 2004
Location:
Western Massachusetts
Posts:
2,361
Plugin Contributions:
1

Re: How do I change the Date format?

same file:

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

Neville
An assumption is what you arrive at when you get tired of thinking...

19 Feb 2007, 5:50 AM
#5
mcpisik avatar

mcpisik

Zen Follower

Join Date:
Jan 2007
Location:
Mount Maunganui, New Zealand
Posts:
417
Plugin Contributions:
0

Re: How do I change the Date format?

bunyip:

same file:

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

Im having the same trouble...maybe u can help?
My examples show that it should be: 21/05/1970, but when user inputs that it comes up   **Is your birth date correct? Our system requires the date in this format: DD/MM/YYYY (eg 21/05/1970)
**I have done this in the php as u indicated but it still only works when usa format is inputed.
Could this be from me having overrides done wrong?
I have the english php in the languages folder and the same changes on another copy of the english php in my languages/custom. 
Thanks for lookin!
31 May 2007, 11:50 AM
#6
crazy avatar

crazy

New Zenner

Join Date:
May 2007
Posts:
38
Plugin Contributions:
0

Re: How do I change the Date format?

I am having the same problem. I have changed all the code about and also the error messages but it still says UK is wrong when i try to enter it. Can any one give me any advise ?

31 May 2007, 12:11 PM
#7
gilby avatar

gilby

Totally Zenned

Join Date:
Aug 2005
Location:
Vic, Oz
Posts:
1,816
Plugin Contributions:
0

Re: How do I change the Date format?

Crazy:

I am having the same problem. I have changed all the code about and also the error messages but it still says UK is wrong when i try to enter it. Can any one give me any advise ?

Remember to alter the english.php in the admin & the catalog sections.
You may have edited the wromg one. You need to edit BOTH

31 Jul 2007, 8:31 PM
#9
phil020782 avatar

phil020782

Zen Follower

Join Date:
Jul 2007
Posts:
158
Plugin Contributions:
0

Re: How do I change the Date format?

I'm having a little trouble changing the date format to dd/mm/yyyy. I managed to get it all changed and it works but in the create account and my account information the example still says 05/21/1970. But it is working in the correct format if you enter it was 05/21/1970 it returns an error saying it should be in the format 05/21/1970.

can anyone help me change the example text please?

31 Jul 2007, 9:40 PM
#10
gilby avatar

gilby

Totally Zenned

Join Date:
Aug 2005
Location:
Vic, Oz
Posts:
1,816
Plugin Contributions:
0

Re: How do I change the Date format?

Phil020782:

I'm having a little trouble changing the date format to dd/mm/yyyy. I managed to get it all changed and it works but in the create account and my account information the example still says 05/21/1970. But it is working in the correct format if you enter it was 05/21/1970 it returns an error saying it should be in the format 05/21/1970.

can anyone help me change the example text please?

You need to edit admin\includes\languages\english.php

and

includes\languages\english.php
(edit and copy this one into your override directory)
includes\languages\YOUR_TEMPLATE\english.php

31 Jul 2007, 10:59 PM
#11
phil020782 avatar

phil020782

Zen Follower

Join Date:
Jul 2007
Posts:
158
Plugin Contributions:
0

Re: How do I change the Date format?

Thanks gilby, I eventually got it working.

For anyone else who wants to know here is what I done step by step to change the date format from mm/dd/yyyy to dd/mm/yyyy:

  1. open file includes/languages/<YOUR_TEMPLATE>/<YOUR_LANGUAGE>.php

  2. find this section around line 22:

@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('DATE_TIME_FORMAT', DATE_FORMAT_SHORT . ' %H:%M:%S');
and replace 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');

  1. in the same file find this section 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 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);
}
}
}

  1. In the same file find this section around line 67:

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

  1. In the same file find this section around line 200:

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)');
and replace with:
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)');

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

  2. Find this section around line 20:

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 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

  1. In the same file find this section around line 29:

// 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 replace with:
// 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);
}
}

  1. In the same file find this section around line 85:

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

  1. In the same file find this section around line 204:

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

  1. In the same file find this section around line 231:

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

  1. Pat yourself on the back, you're all done.
2 Aug 2007, 10:29 AM
#12
eyefultower avatar

eyefultower

New Zenner

Join Date:
Jul 2007
Posts:
77
Plugin Contributions:
0

Re: How do I change the Date format?

Phil020782:

Thanks gilby, I eventually got it working.

For anyone else who wants to know here is what I done step by step to change the date format from mm/dd/yyyy to dd/mm/yyyy:

etc

That all worked sweet, thanks a lot.

4 Aug 2007, 6:30 PM
#13
jaycode avatar

jaycode

Zen Follower

Join Date:
Jun 2007
Location:
Australia - Melbourne
Posts:
306
Plugin Contributions:
1

Re: How do I change the Date format?

Thanks a lot phil! :smartalec:

The greatest pleasure in life is doing what people say you cannot do.

Check on www.WebExtremeCustomiser.com for my modules (free contribution):
AJAX Image Swapper
AJAX Banner Swapper
Fixed Navigation

24 Aug 2007, 11:29 AM
#14
slenderdog avatar

slenderdog

New Zenner

Join Date:
Jul 2007
Posts:
12
Plugin Contributions:
0

Re: How do I change the Date format?

Great, thanks for this Phil!
This post should be referenced in the FAQs....

=========================================
The Organic Store

2 Sep 2007, 8:49 AM
#15
amopro avatar

amopro

New Zenner

Join Date:
Jan 2007
Posts:
35
Plugin Contributions:
0

Re: How do I change the Date format?

I want to change year to Buddhism. I know that I have to add +543 after some function to be corrected. However, I don't know how or where can I edit it?

1 Oct 2007, 9:16 AM
#16
jimcc avatar

jimcc

New Zenner

Join Date:
Sep 2007
Posts:
9
Plugin Contributions:
0

Re: How do I change the Date format?

Just a quick heads up, thank your for this post. It works a treat!

2 Dec 2007, 12:51 PM
#17
phapn avatar

phapn

New Zenner

Join Date:
Nov 2007
Posts:
14
Plugin Contributions:
0

Re: How do I change the Date format?

Thanks :) Worked a treat!:clap:

15 Feb 2008, 8:50 PM
#18
flobster avatar

flobster

New Zenner

Join Date:
Sep 2006
Posts:
76
Plugin Contributions:
1

Re: How do I change the Date format?

Yes that works very well, thank you,

I'm not sure if its planned but wouldnt it be great to have a option in admin to change between US and UK date formats.

18 Feb 2008, 7:44 PM
#19
debbiekipt avatar

debbiekipt

New Zenner

Join Date:
Jan 2008
Posts:
28
Plugin Contributions:
0

Re: How do I change the Date format?

I just wanted to say a HUGE thanks for this Phil!

As someone with no knowledge of programming and new to Zen cart (the person who designed my website chose to use it)
Your step by step instructions were just what I needed to be successful at making the change I wanted to!!

A godsend for a beginner!!
Thanks so much! :clap:

Debbie

28 Feb 2008, 4:44 AM
#20
jillc avatar

jillc

New Zenner

Join Date:
May 2006
Posts:
36
Plugin Contributions:
0

Re: How do I change the Date format?

This was great info, thanks. However, I have been wading through tutorials and little warnings pop up now and again about making sure your files don't get over-ridden during an update. For this reason (AT STEP 6) I copied the file admin/includes/languages/<YOUR_LANGUAGE>.php into
admin/includes/languages/<YOUR_TEMPLATE>/<YOUR_LANGUAGE>.php and made my changes there.

It seems to work and I don't know if I'm just being over cautious or not.
:smile: