calendrier et dates au bon format

Show the correct date format to your visitors

Often, with the use of smarty in your tpl under PrestaShop, you want to display a date in the format corresponding to the language used by your visitors by placing the month and day as it should.

It's quite simple, it always requires a search because you do not practice this kind of change in your code every morning.

Little reminder

As a first step, you should know that this trick works with the format of the standard dates in your databases, of the type YEAR-MONTH-DAY. This format may seem barbaric at first reading but it is totally logical, since it allows to classify in the right order the dates.

In our case

PrestaShop offers a small overload of the Smarty engine with the dateFormat function which must be used as follows:

{dateFormat date = $ your_date full = 0}

If $ your_date is set to 1975-06-04 this will show

in french: 04/06/1975

English translation: 06/04/1975

So the contract is respected.

But the full option is what ????

And you're right to ask me this because it shows the schedule or not, so full = 0 will not show the time while full = 1 will display it.

The format is identical to all languages ​​hh:mm:ss.

Attention, if you use the option full = 1, do not forget to do it with dates containing the schedule otherwise it will always return 00:00:00.


Little end-of-trick gift.

If you want to display the current date and therefore what changes every day, it's better. You have smarty who will help you.


What give something of the style:

{dateFormat date=$|date_format:'%Y-%m-%d' full=0}