Hvor mange dage har du levet?

Prøv beregneren her

Koden:

maaneder = array(
'1' => 'Januar',
'2' => 'Februar',
'3' => 'Marts',
'4' => 'April',
'5' => 'Maj',
'6' => 'Juni',
'7' => 'Juli',
'8' => 'August',
'9' => 'September',
'10' => 'Oktober',
'11' => 'November',
'12' => 'December'); 


$dage = range(1, 31);
$thisYear = date("Y");
$years = range(1900,$thisYear);




echo '<form method="post" action="http://www.anicula.dk/saa-mange-dage-har-du-levet/">';
echo '<label>Dag:</label><select style="margin:1em;" name="Day">';	
foreach ($dage as $dag) {
	    echo '<option value=' . $dag . '><br/>' . $dag . '</option>';
	}	
echo '</select>';
echo '<label>Måned:</label><select style="margin:1em;"name="Month">';	
foreach ($maaneder as $key => $maaned) {
echo '<option value=' . $key . '><br/>' . $maaned . '</option>';
}
echo '</select>';
echo '<label>År:</label><select style="margin:1em;" name="Year">';	
foreach ($years as $aar) {
    echo '<option value=' . $aar . '><br/>' . $aar . '</option>';
}	
echo $aar;
echo '<br/>';
echo '<input style="margin-left:1em;"  type="submit" value="Beregn" name="Beregn">';
echo '</select></form>';

$birthDay = $_POST['Day'];
$birthMonth = $_POST['Month'];
$birthYear = $_POST['Year'];
$birthDate = $birthYear . '-' . $birthMonth . '-' . $birthDay;
$datetime1 = new DateTime($birthDate);
$datetime2 = new DateTime($todaysDate);
$interval = $datetime1->diff($datetime2);

echo '<p style="font-size:1.5em;color:red;font-style:italic;">Tillykke! Du har levet i ' . $interval->format('%a dage') . '<br/>Carpe Diem!</p>';