tenfour tenfour - 1 year ago 104
Smarty Question

Smarty Template date_format gives unpredictable results

I am passing a timestamp into a Smarty Template, and using

gives unpredictable results. Here's an example template that demonstrates the problem most elegantly:


The output of this template:

Oct 19, 2208
May 28, 2015

The second date is correctly formatted. The first one, however, should be

Feb 27, 2016

Why is this?

Answer Source

The best way to avoid this is to cast to int the timestamp. Now it's a numeric string.

Smarty did some changes in 2.6.10 to use all numeric input values as timestamp, but before was not always the case.

As I can see the first timestamp ends in 2208 and also the year returned for that timestamp is 2208, so I think smarty think it's not a timestamp, but a date formatted somehow.

See more here (smarty doc)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download