paulalexandru paulalexandru - 3 months ago 25
HTML Question

Smarty 1 month ago date

I have

in my html file and I want to see if this comment was posted in the past month or it's older than that.

I know that I need to do something like:

{if $comment->date|strtotime < $}

but I don't know exactly how can I get the 1 month ago date.


Hei Paul! You have few options here.

First thing crossing my mind would be to check if the comment's timestamp compared to the current timestamp is more than a month's value in seconds, as follows:

{ if ( $ - $comment->date|strtotime ) > 2592000 }

On a side note, as a second idea, date_format uses strtotime so implicitly it will accept whatever strtotime accepts. Therefore you can try using the following, though it's not faster nor as elegant as the above.

{ if $comment->date|strtotime < '-1 month'|strtotime }

Update, fixed plus sign typo and removed date_format