Created
September 9, 2015 06:53
-
-
Save mymizan/b30bdf4ea0f289f7b148 to your computer and use it in GitHub Desktop.
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 | |
/** | |
* 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