Last active
September 6, 2020 23:33
-
-
Save versluis/c62a6bbfe95be8d42db3ce0df87ce127 to your computer and use it in GitHub Desktop.
Calculates how many years I've been married to Julia :-)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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