paulalexandru paulalexandru - 1 year ago 199
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.

Answer Source

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

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