Post by mazman » Wed Jan 08, 2025 1:41 am

I have read many many posts on how to change the date format and none are working for me. Version 3.0.4.0. Trying to get it to read Month/Day/Year. And it only has to be that way on the front end. I've changed the values in catalog/language/en-gb/en-gb.php, (also in admin/language/en-gb/engb.php), cleared the cache in OC, also in the browser and it keeps coming up as Day/Month/Year. I've spent literal hours scouring these postings as I did not want to ask this question which has been asked a hundred times, but the solution evades me.

New member

Posts

Joined
Sun Apr 03, 2022 5:20 am

Post by johnp » Wed Jan 08, 2025 3:17 am

Try this. It works for me:

https://www.opencart.com/index.php?rout ... n_id=27267

Make sure you refresh the modification cache after installing.

Opencart 1.5.6.5/OC Bootstrap Pro/VQMOD lover, user and geek.
Affordable Service £££ - Opencart Installs, Fixing, Development and Upgrades
Plus Ecommerce, Marketing, Mailing List Management and More
FREE Guidance and Advice at https://www.ecommerce-help.co.uk


User avatar
Active Member

Posts

Joined
Fri Mar 25, 2011 10:25 am
Location - Surrey, UK

Post by mazman » Wed Jan 08, 2025 4:16 am

johnp wrote:
Wed Jan 08, 2025 3:17 am
Try this. It works for me:

https://www.opencart.com/index.php?rout ... n_id=27267

Make sure you refresh the modification cache after installing.
Thanks but this says it changes the date to the US date format d/m/Y, whereas the US date format is m/d/Y. I would like m/d/Y

New member

Posts

Joined
Sun Apr 03, 2022 5:20 am

Post by johnp » Wed Jan 08, 2025 6:14 am

mazman wrote:
Wed Jan 08, 2025 4:16 am
johnp wrote:
Wed Jan 08, 2025 3:17 am
Try this. It works for me:

https://www.opencart.com/index.php?rout ... n_id=27267

Make sure you refresh the modification cache after installing.
Thanks but this says it changes the date to the US date format d/m/Y, whereas the US date format is m/d/Y. I would like m/d/Y
If you have the Modification Manager extension you can install the Ocmod then edit it online to get the format you need.

https://www.opencart.com/index.php?rout ... n_id=22318

Opencart 1.5.6.5/OC Bootstrap Pro/VQMOD lover, user and geek.
Affordable Service £££ - Opencart Installs, Fixing, Development and Upgrades
Plus Ecommerce, Marketing, Mailing List Management and More
FREE Guidance and Advice at https://www.ecommerce-help.co.uk


User avatar
Active Member

Posts

Joined
Fri Mar 25, 2011 10:25 am
Location - Surrey, UK

Post by nonnedelectari » Wed Jan 08, 2025 10:08 am

Extension quote:
Change short date to US format d/m/Y. It accomplish this by changing the date_format_short variable in the language file of english directory.
That sounds exactly like what the OP tried manually.

Active Member

Posts

Joined
Thu Mar 04, 2021 6:34 pm

Post by mazman » Thu Jan 09, 2025 4:00 am

Still no luck. when I look at the Catalog/Language/en-gb/en-gb.php file, it is showing the short date as 'm/d/Y' but they do not appear that way on the front end. I did save the file using Notpad++ with encoding simply as UTF-8 (no BOM).

New member

Posts

Joined
Sun Apr 03, 2022 5:20 am

Post by OSWorX » Thu Jan 09, 2025 3:28 pm

Maybe post once a time in which template you want to change the date format, or which action.
Because often these dates are hardocded inside the corresponding controller.

Full Stack Web Developer :: Dedicated OpenCart Development & Support DACH Region
Contact for Custom Work / Fast Support.


User avatar
Administrator

Posts

Joined
Mon Jan 11, 2010 10:52 pm
Location - Austria

Post by nonnedelectari » Thu Jan 09, 2025 6:10 pm

mazman wrote:
Thu Jan 09, 2025 4:00 am
Still no luck. when I look at the Catalog/Language/en-gb/en-gb.php file, it is showing the short date as 'm/d/Y' but they do not appear that way on the front end. I did save the file using Notpad++ with encoding simply as UTF-8 (no BOM).
The main language files are loaded at startup in catalog/controller/startup/startup.php.
There it creates a new language object which in turn loads the default en-gb.php file (containing array definitions) and the current language file if present and it merges these array key-values. I assume so that if a language definition is missing, the en-gb is always there as a fallback.

you could add something like:

Code: Select all

$this->log->write('date short definition: '. $this->language->get('date_format_short'));
after:

Code: Select all

$this->registry->set('language', $language);
in that file and see in your oc log if it is correct.
If it is, that value is overwritten somewhere or simply not used.

Active Member

Posts

Joined
Thu Mar 04, 2021 6:34 pm

Post by mazman » Fri Jan 10, 2025 4:59 am

nonnedelectari wrote:
Thu Jan 09, 2025 6:10 pm
mazman wrote:
Thu Jan 09, 2025 4:00 am
Still no luck. when I look at the Catalog/Language/en-gb/en-gb.php file, it is showing the short date as 'm/d/Y' but they do not appear that way on the front end. I did save the file using Notpad++ with encoding simply as UTF-8 (no BOM).
The main language files are loaded at startup in catalog/controller/startup/startup.php.
There it creates a new language object which in turn loads the default en-gb.php file (containing array definitions) and the current language file if present and it merges these array key-values. I assume so that if a language definition is missing, the en-gb is always there as a fallback.

you could add something like:

Code: Select all

$this->log->write('date short definition: '. $this->language->get('date_format_short'));
after:

Code: Select all

$this->registry->set('language', $language);
in that file and see in your oc log if it is correct.
If it is, that value is overwritten somewhere or simply not used.
I tried the above but see no reference to the short date in the logs. I looked in the https logs, the storage/logs, and also the logs from the dashboard>system>maintnance>error logs. Are there others I should be looking at? I liked this approach to the issue.

New member

Posts

Joined
Sun Apr 03, 2022 5:20 am

Post by nonnedelectari » Fri Jan 10, 2025 9:15 am

whenever you use this:

Code: Select all

error_log(....);
it goes into your PHP error log which your provider can tell you where to find.

whenever you use this:

Code: Select all

$this->log->write(....);
it goes into your OC's own error log which you can view in admin under system->maintenance->error logs.

you did put that statement in file catalog/controller/startup/startup.php after:

Code: Select all

$this->registry->set('language', $language);
right?

Active Member

Posts

Joined
Thu Mar 04, 2021 6:34 pm

Post by mazman » Fri Jan 10, 2025 9:42 pm

nonnedelectari wrote:
Fri Jan 10, 2025 9:15 am
whenever you use this:

Code: Select all

error_log(....);
it goes into your PHP error log which your provider can tell you where to find.

whenever you use this:

Code: Select all

$this->log->write(....);
it goes into your OC's own error log which you can view in admin under system->maintenance->error logs.

you did put that statement in file catalog/controller/startup/startup.php after:

Code: Select all

$this->registry->set('language', $language);
right?
Yes sir. Here a snippet I just copied from the startup.php file:
// Overwrite the default language object
$language = new Language($code);
$language->load($code);

$this->registry->set('language', $language);
$this->log->write('date short definition: '. $this->language->get('date_format_short'));

New member

Posts

Joined
Sun Apr 03, 2022 5:20 am

Post by nonnedelectari » Fri Jan 10, 2025 11:29 pm

Your OC error log under admin under system->maintenance->error logs is completely empty?
Then look in your PHP error log, not the webserver logs, ask your host where it is located, could be that you have an issue with your OC error log.
Double check that you have it defined in system->settings->server tab "Error Log Filename".

Active Member

Posts

Joined
Thu Mar 04, 2021 6:34 pm

Post by sedangroup » Tue Jan 14, 2025 7:59 am

If you've updated the date format in your language files but the changes aren't reflected on the front end, the issue might be related to how OpenCart loads and uses language definitions. Here’s how to troubleshoot and resolve it:

1. Ensure the Correct Date Format
In your catalog/language/en-gb/en-gb.php file, verify that the date_format_short value is set to m/d/Y:

Code: Select all

 $['date_format_short'] = 'm/d/Y'; $['date_format_long'] = 'l dS F Y'; 
Also, ensure you’ve updated the same in admin/language/en-gb/en-gb.php for consistency.

2. Clear Caches
After making changes to the language files:

Clear OpenCart’s modification cache: Go to Dashboard → Extensions → Modifications, and click the "Refresh" button.
Clear theme cache: If your theme uses caching, clear the cache from the theme's admin settings.
Clear browser cache to ensure you're not viewing old cached data.

3. Check Hardcoded Date Formats
Some date formats might be hardcoded in templates, controllers, or models.

Search for Hardcoded Date Formats:
Use a file search tool (e.g., grep, VS Code, or Notepad++) to look for instances of d/m/Y or date_format_short across the catalog folder.

If you find a hardcoded format like d/m/Y, replace it with your desired format (m/d/Y).

4. Add Logging to Verify Loaded Values
To confirm that the date_format_short is correctly loaded from the language file, add the following line to catalog/controller/startup/startup.php after:

Code: Select all

 $this->registry->set('language', $language); 
Add:

Code: Select all

 $this->log->write('date short definition: ' . $this->language->get('date_format_short')); 
Check the OpenCart error log under System → Maintenance → Error Logs for the logged output.
If the log is empty, check your PHP error log. Contact your hosting provider for its location.

5. Check Your Theme
Some custom themes may override the core OpenCart logic for rendering dates.

Check Theme-Specific Files:

Look for date formatting in the following:
catalog/view/theme/<your_theme>/template/
JavaScript files (for frontend rendering).

6. Debug the Issue Further
If the above steps don’t work:

Check if the correct language file is loaded in catalog/controller/startup/startup.php.
Verify the fallback behavior in catalog/language/en-gb/en-gb.php. If a key is missing in the selected language file, OpenCart uses the default en-gb values.

7. If All Else Fails
Your issue might be related to an override or modification. Check for installed OCMOD or VQMOD modifications that could affect date handling.
Disable these modifications temporarily and test again.

Newbie

Posts

Joined
Tue Jan 14, 2025 7:11 am

Post by paulfeakins » Tue Jan 14, 2025 9:05 pm

@sedangroup

You seem to be just pasting from ChatGPT and the answers aren't great.

I suggest you start writing answers yourself.

UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


User avatar
Legendary Member

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom
Who is online

Users browsing this forum: Amazon [Bot] and 11 guests