paulalexandru paulalexandru - 18 days ago 5
HTML Question

Smarty 1 month ago date

I have

{$comment->date|strtotime}
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 < $smarty.now-1m}


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

Answer

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 ( $smarty.now - $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

Comments