1

I need to display a message if an entry is more than 90 days old. The below code doesn't appear to be working, any tips on how to get this done?

{if {current_time} > {entry_date} + 7776000 }
    <div id="message">
        <h4>Your safety training is out of date.</h4>
    </div>
{/if}
0

You can't do math in an EE template without an an add-on; Will Hunting is my favorite, although there are others.

Edit: You couldn't do math in an EE template, within a conditonal, until the relatively recent EE 2.9.0; if you have an older install than that, you have to upgrade and/or use the add-on I mentioned.

2
0

It's proably becasue the tag in normal format outputs a string representation of the date, try the below which causes the output to be done as a UNIX Epoch time :

(Tested on EE 2.7.1)

{if {current_time format="%U"} > ( {entry_date format="%U"} + 7776000 ) }
  <div id="message">
    <h4>Your safety training is out of date.</h4>
  </div>
{/if}

Or , you could use a PHP flavour (if EE is having a string/number issue in the tags) :

PHP On Output

<?php
  if ( intval('{current_time format="%U"}') > ( intval('{entry_date format="%U"}') + 7776000 ) { ?>
    <div id="message">
      <h4>Your safety training is out of date.</h4>
    </div>
<?php } ?>
4
  • PHP in the template is a bad habit to fall into, and math within a conditional will only work in EE 2.9.0+. Downvote karma to you, kind sir. – Nick Benson Aug 19 '15 at 16:02
  • I'm not sure where you're getting info from but I've just run my example above up in EE 2.7 and it works fine (I had to add brackets, which I've added above too). My understanding is (as I have a few older projects on 2.5.2) mathamatical operators have worked in EE since around version 2 but they definatly work in EE2.5+. – Blatant Aug 20 '15 at 16:45
  • Also PHP in templates is not a bad habit, it wouldn't be available if it was. What is a bad habit is throwing plugin after extension into a build to solve single use cases. If you don't beleive me fire up the profiler and look at the lag adding and parsing module tags costs opposed to a simple bit of PHP Date maths (PHP on templates is not for establishing complex class interactions ect). That being said I still teach and advise to avoid it if possible, its a case of the right tool for the right job. Anyway, question solved so Glad you got going Koala!! – Blatant Aug 20 '15 at 16:48
  • @NickBenson , I'm not sure what kind of applications you've developed, but their is distinct workflows that make PHP in template perfectly acceptable. The only people (@ my work) who have access to template code are developers, not content editors, making it perfectly acceptable at times to turn PHP on in a template. Each situation requires assessment, and throwing tools out of your toolbox is stupid. – jrothafer Aug 21 '15 at 12:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.