How Old is Reactuate Exactly?

on

I was looking at the blog today and noticed the calculation I talked about in the post How to Add a Running Total of How Long You’ve Blogged To Thesis was broken. The days were negative for one thing.

I decided I better update it. I don’t know if PHP has changed since then, or I’ve just gotten better, but it is way easier now to code this. The details on how to add this to Thesis are in the previously mentioned post, so I’m just giving you the new routine.

[cc lang=”php”]function custom_footer() {
date_default_timezone_set(‘America/Chicago’);
$startDate = new DateTime(‘2002-10-28’);
$todayDate = new DateTime(‘now’);
$interval = $startDate->diff($todayDate);
echo “

Blogging for “.$interval->format(‘%y years, %m months, %d days’).”

\n”;
echo “

Copyright 2002-“.date( “Y” ).” Ron Davis. All rights reserved.

\n”;
echo “

Get smart with the Thesis WordPress Theme from DIYthemes.

“;
}
[/cc]

I’m not sure line 2 is needed, but I was testing the code from the command line on my laptop and had to add that line to get rid of the really annoying php warning.

The thing that makes this so much simpler than the previous incarnation is the diff routine. It basically does all the math for you. Then you just use DateTime’s format method to output exactly what you need.

It also turns out all that math I was doing before to calculate years from days was just wrong. Think about leap years. It makes my head hurt just thinking about it. Also have to say, this is one of the few things I think PHP does better than Python. Look at the headaches involved with calculating years in Python.

If the days aren’t right in the footer of the blog, this is probably caused by my blog being cached by WP Super Cache. I think it might be better to make this a widget rather than a custom function in Thesis, but that is project for another insomniac night.