<html>
<head>
  <title>Дата на раждане</title>
</head>
<body>
	  
<center>
<form action="age.php" method=post>
<table align=center border=0>
<tr bgcolor=#cccccc>
  <td colspan="2"><center>Дата на раждане</center></td>
</tr>
<tr>
  <td>Година</td>
  <td align=left><input type="text" name="cdoby" size=3 maxlength=4></td>
</tr>
<tr>
  <td>Месец</td>
  <td align=left><input type="text" name="cdobm" size=3 maxlength=2></td>
</tr>
<tr>
  <td>Ден</td>
  <td align=left><input type="text" name="cdobd" size=3 maxlength=2></td>
</tr>
<tr>
  <td colspan=2 align=center><input type=submit value="Изчисли възрастта"></td>
</tr>
</table>
</form>  
</center>
<?php
  $cdoby = $HTTP_POST_VARS['cdoby'];
  $cdobm = $HTTP_POST_VARS['cdobm'];
  $cdobd = $HTTP_POST_VARS['cdobd'];
  
//script za presmqtane na godinite
	// godina
				
$yage = "$cdoby";  	// $yage e string
$yage += 0;   	
	// mesec
$mage = "$cdobm";  // $mage e string
$mage += 0;   	// $mage e integer--
	//   data
$dage = "$cdobd";  // $dage e string
$dage += 0;   
				
	//kalkulirane na godinite
$leap = date("L");  		
$nowday = date("d");	
$nowday += 0;	
$lnowday = ($nowday + $leap); 
$nowmonth =date("m");	
$nowmonth += 0;	// konvertirane na  data string w istinski/pravilen integer
$myyear = date("Y"); 	//4 digit number		
$age = ($myyear-$yage);  
if (($nowmonth < $mage) OR (($nowmonth < $mage) AND ($lnowday < $dage))) {
   $age=$age-1;
}
?>
<center>
 <? if (($cdoby > 0) AND ($cdobm > 0) AND ($cdobd > 0)) { echo ' <b>Човекът роден на '.$cdobd.'.'.$cdobm.'.'.$cdoby.' г. в момента е на '.$age.' години.</b>'; } 
 	   else { echo 'Моля въведете дата на раждане'; } ?>
</center>
</body>
</html>
П.П ДИР-а ми изяде <бр>
"Vivere est cogitare"Редактирано от Chavdarov на 05.02.06 23:05.