Skip to content

Instantly share code, notes, and snippets.

@versluis

versluis/yearsmarried.php

Last active Sep 6, 2020
Embed
What would you like to do?
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