Skip to content

Instantly share code, notes, and snippets.

@davidsword
Last active February 3, 2018 03:00
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 davidsword/006a7b0ee5cce0640a590bf4bd2053f0 to your computer and use it in GitHub Desktop.
Save davidsword/006a7b0ee5cce0640a590bf4bd2053f0 to your computer and use it in GitHub Desktop.
<?
add_shortcode('years','ds_years_since');
function ds_years_since($atts) {
$a = shortcode_atts( array('since' => date('r')), $atts );
$then = new DateTime($a['since']);
$now = new DateTime();
$interval = date_diff($then, $now);
return $interval->y;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment