responder Posted September 18, 2011 Share Posted September 18, 2011 How can I change the date format that appears on PDF Invoice etc Need it to show (NZ format) 18/09/2011 instead of 2011/09/18. Thanks Link to comment Share on other sites More sharing options...
Mallee Boy Posted September 22, 2011 Share Posted September 22, 2011 Me too! Link to comment Share on other sites More sharing options...
Mallee Boy Posted September 22, 2011 Share Posted September 22, 2011 #SOLVED# To set date to DD-MM-YY across the whole site Edit /classes/Tools.php Search (Ctrl+F) for → if ($language AND strtolower($language['iso_code']) On the same line that is now highlighted, change fr to uk 3 lines below that, replace the existing line with → return ($tmpTab[2].'-'.$tmpTab[1].'-'.$tmpTab[0].($full ? $hour : '')); Link to comment Share on other sites More sharing options...
pakatemp Posted September 22, 2011 Share Posted September 22, 2011 return ($tmpTab[2].'-'.$tmpTab[1].'-'.$tmpTab[0].($full ? $hour : '')); will output as: DD-MM-YYYY (NZ format) return ($tmpTab[1].'-'.$tmpTab[2].'-'.$tmpTab[0].($full ? $hour : '')); will output as: MM-DD-YYYY (US format) Link to comment Share on other sites More sharing options...
responder Posted September 25, 2011 Author Share Posted September 25, 2011 When I do the above, then add item to cart and click checkout I get a balnk screen at order step 1. Get the same if I select cart, then next. Not sure what I'm missing? Link to comment Share on other sites More sharing options...
DeepVoid Posted December 17, 2011 Share Posted December 17, 2011 What happens when I upgrade PS with a new release? Will the classes/tools.php file be overwritten by the upgrade procedure? It should be a common custom not to touch any of the core files in PS. Isn't there an alternative way to format dates across the web site? This matter is fundamental for PDF invoices, which often sport date format unsuitable for european customers. Link to comment Share on other sites More sharing options...
bellini13 Posted December 17, 2011 Share Posted December 17, 2011 What happens when I upgrade PS with a new release? Will the classes/tools.php file be overwritten by the upgrade procedure? It should be a common custom not to touch any of the core files in PS. Isn't there an alternative way to format dates across the web site? This matter is fundamental for PDF invoices, which often sport date format unsuitable for european customers. The correct way is to override the class file in the override directory, and only override the function you need to change. This way in the future if the class changes, you still have your customization in the override folder, and only impact the single function you override, and not the entire class. Note: This is not fool proof, since future versions of prestashop may change the functionality you override to the point it needs to be redone. The date format is a good example. In prior versions, the date format was performed within Tools.php. However now (v1.4.6.2) the date format is now defined within the Language definition in the back office. If you want to change the date format for the entire site in v1.4.6.2, just go into the back office, and update the Language date format. However in previous versions, let's say v1.4.4.1, you would do it like this... 1) Create a file called Tools.php in the override/classes folder, and add the following content class Tools extends ToolsCore { } 2) Now add the function that you want to change to this class file. To change the date format for the entire site you would override the displayDate function. public static function displayDate($date, $id_lang, $full = false, $separator = '-') { if (!$date OR !strtotime($date)) return $date; if (!Validate::isDate($date) OR !Validate::isBool($full)) die (self::displayError('Invalid date')); $tmpTab = explode($separator, substr($date, 0, 10)); $hour = ' '.substr($date, -8); $language = Language::getLanguage((int)($id_lang)); if ($language AND strtolower($language['iso_code']) == 'fr') return ($tmpTab[2].'-'.$tmpTab[1].'-'.$tmpTab[0].($full ? $hour : '')); else return ($tmpTab[0].'-'.$tmpTab[1].'-'.$tmpTab[2].($full ? $hour : '')); } 3) Now change the logic so it does what you want it to. You have successfully customized the logic without modifying the core file. If you only want to impact the invoice, following the same steps above, but instead override the PDF.php class file. This is a bit more complicated, because you have to override every single function that uses displayDate, but it is less intrusive and will avoid issues that you are running into with the cart. I suspect the cart made some assumption about the date format, without using the Tools.php class. 1 Link to comment Share on other sites More sharing options...
e.pravicar Posted December 17, 2011 Share Posted December 17, 2011 Hi there, I'm using version 1.4.5.1 and here is obviously different Tools.php since I can't find the lines from those posts. Does anybody know how to change the date format in this version? Link to comment Share on other sites More sharing options...
bellini13 Posted December 17, 2011 Share Posted December 17, 2011 v1.4.5.1 has the new functionality. go into the back office, under the Tools | Languages section. Edit the language you want to change the format for. You will see there are 2 date fields, edit the format appropriately. 1 Link to comment Share on other sites More sharing options...
e.pravicar Posted December 18, 2011 Share Posted December 18, 2011 Many thanks bellini13! You are the man Link to comment Share on other sites More sharing options...
kkm Posted May 6, 2013 Share Posted May 6, 2013 (edited) When I change the date format from y-m-d to dd-mm-yyyy it changes it but also throws an error: "An error occurred while updating an object. lang ()" PS version 1.5.4.1 Edited May 6, 2013 by kkm (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now