Hi, I have a website that contains listings for different chapters in our organization. We require each chapter to update their information once per year. I want to display a small green icon beside the date for chapters that have updated within the past year and something else, maybe a small red icon for chapters that need to submit an update. I am using the code below to display the date of the last update in my content template teaser:
<?php print("Last Updated : ".date("M j, Y", $node->changed)); ?>
I want to compare the last updated date with the current date and display the green icon if the difference is less than 365 days, and the other one if the difference is more. Could someone help me with the php code for that?

Thank you!

Comments

nevets’s picture

// Calculate one year from the last  change
$one_year = strtotime("+1 year",$node->changed);
$today = time();
if  ( $today > $one_year ) {
  $class = "out-of-date";
}
else {
   $class =  "up-to-date";
}
print '<span class="' . $class  . '">Last Update: '  .  date("M j, Y", $node->changed)  .  '</span>';

You can this use css to apply a background image to the span based on the class.

bshaf’s picture

Wow, thank you SO much. I will implement this right away.

UPDATE: Worked like a charm! Thanks again!!!