Skip to content

Instantly share code, notes, and snippets.

@versluis
Last active September 6, 2020 23:33
Show Gist options
  • Save versluis/c62a6bbfe95be8d42db3ce0df87ce127 to your computer and use it in GitHub Desktop.
Save versluis/c62a6bbfe95be8d42db3ce0df87ce127 to your computer and use it in GitHub Desktop.
Calculates how many years I've been married to Julia :-)
<?php
function guru_yearsmarried() {
// dates to be calculated
$dateMarried = strtotime( '2004-04-22 15:00:00' );
$currentDate = strtotime( current_time ( 'mysql' ));
// calculate the time in seconds and convert
$seconds = $currentDate - $dateMarried;
$years = $seconds / 60 / 60 / 24 / 365.242199;
return round ($years);
}
// register shortcode
function guru_shortcodes() {
add_shortcode( 'yearsmarried', 'guru_yearsmarried' );
}
add_action( 'init', 'guru_shortcodes' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment