Skip to content

Instantly share code, notes, and snippets.

@mattrude
Created April 22, 2011 02:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattrude/935898 to your computer and use it in GitHub Desktop.
Save mattrude/935898 to your computer and use it in GitHub Desktop.
WordPress Plugin to display the time since a entered date.
<?php
/*
Matt Rude <matt@mattrude.com> - 1 Nov 2009
This shortcode displays the years since the date provided.
To use this shortcode, add some text to a post or page simmiler to:
[ts date='1983-09-02']
The date format is YYYY-MM-DD
*/
function mdr_timesince($atts, $content = null) {
extract(shortcode_atts(array("date" => ''), $atts));
if(empty($date)) {
return "<br /><br />************No date provided************<br /><br />";
}
$mdr_unix_date = strtotime($date);
$mdr_time_difference = time() - $mdr_unix_date ;
$years = floor($mdr_time_difference / 31556926 );
$num_years_since = $years;
return $num_years_since;
}
add_shortcode('ts', 'mdr_timesince');
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment