Scripts

Leeftijd Berekenen (Jaar,maanden,dagen,uur minuten)

Spreekt eigenlijk voor zich. Dit script berekent met je leeftijd in jaren, maanden dagen uur en minuten. Het script is ook schrikkeljaar proof. Een voorbeeld kun je zien op http://www.saravanwesel.nl Een site welke ik heb gemaakt voor het dochtertje van mijn zus. Let er op dat je de variabelen invult met "voorloppnullen". Wanneer je dit niet doet zal het script zich vreemd gedragen.

leeftijd-berekenen-jaarmaandendagenuur-minuten
<?
$birth['year'] 	= "2005";
$birth['month'] 	= "08";
$birth['day'] 	= "23";
$birth['hour'] 	= "04";
$birth['minute'] 	= "36";

if ($birth['minute'] > date("i"))			
	{
	$total['minute'] = (60 - $birth['minute'] + date("i"));
	$total['hour'] = -1;
	}
else
	{
	$total['minute'] = (date("i") - $birth['minute']);
	}

if ($birth['hour'] > date("H"))
	{
	$total['hour'] = ($total['hour'] + (24 - $birth['hour'] + date("H")));
	$total['day'] = -1;
	}
else
	{
	$total['hour'] = ($total['hour'] + (date("H") - $birth['hour']));
	}

if ($birth['day'] > date("d"))
	{
	$total['day'] = ($total['day'] + (date("t",mktime(00,00,00,(date("m") - 1),01,date("Y"))) - $birth['day'] + date("d")));
	$total['month'] = -1;
	}
else
	{
	$total['day'] = ($total['day'] + (date("d") - $birth['day']));
	}

if ($birth['month'] > date("m"))
	{
	$total['month'] = ($total['month'] + (12 - $birth['month'] + date("m")));
	$total['year'] = -1;
	}
else
	{
	$total['month'] = ($total['month'] + (date("m") - $birth['month']));
	}

$total['year'] = ($total['year'] + (date("Y") - $birth['year']));



echo("<div>");
echo("Sara is nu ");
if ($total['year'] > 0)		{ echo("".$total['year']." jaar "); }
if ($total['month'])		{ echo("".$total['month']." maand"); if ($total['month']!=1){echo("en");}}
echo(" ");
if ($total['day'])			{ echo("".$total['day']." dag"); if ($total['hour']!=1){echo("en");}}
echo(" ");
if ($total['hour'])			{ echo("".$total['hour']." uur "); }
echo("en ");
if ($total['minute'])		{ echo("".$total['minute']." minuten "); }
echo("oud.");
echo("</div>");

?>

Reacties

0
Nog geen reacties.