If I have a smarty variable
{$test.date_created}
that displays a date in a smarty template, for example:
02/2/2012
On the smarty website, it says that you can display today’s date with the following.
{$smarty.now|date_format:'%m/%d/%Y'}
How can I use it in an if statement to display a message when its 3 days old or more from today’s date?
If its 3 days old or more, display “Old”. If not, Display “New”.
You can use
strtotime()to get the timestamp corresponding to three days ago, and then compare this to the date of your message. For example, assuming$messageis your message record and$message['date']is the timestamp you have to check:And then, in your template:
I’m not 100% sure, but you can also test it directly in Smarty. Assuming you have
$messagepassed to Smarty: