function days_to_birthday birthday born explode birthday list day mont

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
function days_to_birthday($birthday) {
$born = explode('.', $birthday);
list($day, $month) = $born;
$now = time();
$year_now = date("Y");
$next_birthday = mktime(0, 0, 0, $month, $day, $year_now);
$days_to_birthday = round(($next_birthday - $now)/(60*60*24));
if ($days_to_birthday > 0) {
return $days_to_birthday;
} elseif ($days_to_birthday == 0) {
return 'Сегодня ваш день рождения! Поздравляем!!)';
} else {
if (checkdate(2, 29, $year_now+1)) {
$days_to_birthday = 366 + $days_to_birthday;
} else {
$days_to_birthday = 365 + $days_to_birthday;
}
return $days_to_birthday;
}
}
function get_life_days($birthday) {
$born = explode('.', $birthday);
list($day, $month, $year) = $born;
$now = time();
$days_lived = round(((mktime(0, 0, 0, $month, $day, $year) - $now)/(60*60*24))*-1);
if ($days_lived > 0) {
return $days_lived;
} else {
return 'Введена неправильная дата';
}
}
function days_to_live($birthday) {
$death_days = 70 * 365.24;
$days_to_live = round($death_days - get_life_days($birthday));
return $days_to_live;
}
function get_life_percent($birthday) {
$life_days = get_life_days($birthday);
$life_percent = round(($life_days/($life_days+days_to_live($birthday)))*100);
return $life_percent . '% жизни прожито';
}
$birthday = '22.06.1991';
echo days_to_birthday($birthday) . ' дней до дня рождения' . "\n";
echo get_life_days($birthday) . ' дней прожито' . "\n";
echo days_to_live($birthday) . ' дней осталось жить' . "\n";
echo get_life_percent($birthday);