If you use Smarty for your templating engine, I’m sure you’ve had to format dates to different formats before. This is a handy modifier plugin which converts a date into something human friendly such as “2 minutes ago”, “Tuesday at 3:52pm”, or “March 12 at 6:49am” much like Facebook does. Works great for comments and message boards!

Simply download it, and extract “modifier.timeSpan.php” into your Smarty/plugins/ directory. To use it, simply add the “timeSpan” modifier to any smarty date variable. For example… {$postDate|timeSpan}

It takes advantage of PHP’s strtotime() function, so just about any date format you input should work just fine, but it works best with the YYYY-MM-DD HH:MM:SS format.

Possible outputs are…
Just now // less than 3 minutes ago
5 minutes ago // less than an hour ago
9 hours ago // less than 24 hours ago
Yesterday at 10:15pm // yesterday
Tuesday at 2:45pm // less than 5 days go
October 8 at 1:30am // more than 5 days ago this year
August 18 2007 at 5:32pm // not this year or in the future