Date formatting in Smarty

If you use the so called, German date format (day of month. month. year) you may have wondered how to achieve it with Smarty - without the leading zeroes for month.

You all know the common way to format date in Smarty:

  1. {$myDate|date_format:"%e. %m. %Y"}

If you ever wanted to have month number without the leading zeroes, here’s how:

  1. {$myDate|date_format:"%e. %#m. %Y"}

or even a cooler way:

  1. {assign var="myDateTimestamp" value=$myDate|strtotime}
  2. {"j. n. Y"|date:$myDateTimestamp}

(because you can use almost any PHP function as Smarty variable modifier, just solve the parameters-order problem)

Question

Got any better solution? Tell me about it!

Leave a Reply