Skip to content

Instantly share code, notes, and snippets.

@mymizan
Created September 9, 2015 06:53
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 mymizan/b30bdf4ea0f289f7b148 to your computer and use it in GitHub Desktop.
Save mymizan/b30bdf4ea0f289f7b148 to your computer and use it in GitHub Desktop.
<?php
/**
* Calculate your life expectancy and
* send a notification email every day
*/
//set the default timezone to UTC
date_default_timezone_set('UTC');
/**
* Return the date object with life expectancy
* @param integer $birthDate birth date string eg 1990-2-20
* @param integer $expectancy life expectancy eg 79
* @return DateInterval DateInterval object
*/
function spit_life_expectancy($birthDate, $expectancy) {
$now = new DateTime("now"); //time now
$exp = new DateTime($birthDate); //begening of your life
$exp->add(new DateInterval("P{$expectancy}Y"));
return $now->diff($exp); //return the object
}
$expectancy = spit_life_expectancy('1990-05-21', 80);
$exptancy = "Life Expectancy: {$expectancy->y} years, {$expectancy->m} months, {$expectancy->d} days";
echo $exptancy;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment