I am putting together a site for my daughter... she's at that age where everything she says is utterly hilarious, so I'd like to document some of it so she can see it when she's older.

What I am looking to do is have my posted date formatted to show her age. For instance, instead of showing "Posted: Thu, 2010-07-01 18:10" I would like it to say "Age: 4 years, 9 months, 18 days"

Any ideas?

Comments

Bill Bostick’s picture

Override the theme_node_submitted function in your theme's template.php file... something along the lines of:

function garland_node_submitted($node) {
  $date1 = "2004-01-15";
  $date2 = $node->created;
  $diff = abs($date2 - strtotime($date1));
  $years = floor($diff / (365*60*60*24));
  $months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
  $days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
  return("Age: " . $years . " years, " . $months . " months, " . $days . " days.");
}

where date1 is your daughter's birth date.

m_i_c_h_a_e_l’s picture

This is a wonderful little mod.

My question is, when I override the template.php file, how do I avoid losing the mod when I update the theme?

Do I create something like a local.template.php, or do I just reedit the file after the update?

Bill Bostick’s picture

If you're doing this on a large scale where you need to track such changes across multiple sites, you probably use something like Subversion's vendor branching capabilities. If you're doing this for your daughter's blog, you just re-edit the file after the update.

aflores3’s picture

Bill,
This worked like a charm. Thanks for the quick response.

Michael,
I don't have an answer for you right off the top, but I'll research it and try to reply to this thread as I will obviously need this functionality too.