| 
	
 | 
 
           
             
               
               
                 
                   | 
                   Тема
                    | 
                     изчисляване на възраст 
 | 
 
 |  
| Автор | pitasht (Нерегистриран) |  
| Публикувано | 05.02.06 11:03 |  
             |  
           | 
            
           
  има следния проблем - по рожденна трябва да определя точната възраст на човек
 
 с mktime няма проблеми - но така може да се изчисли възрастта на хора родени след 1970 г. как да изчисля възрастта на тези родени преди 1970 г.
 
 ще съм ви благодарен за всякакви съвети
  
           
  
             |   |  
           
             
               
               
                 
                   | 
                   Тема
                    | 
                     Re: изчисляване на възраст 
[re: pitasht]
 | 
 
 |  
| Автор | 
Sanndo (WebDevPich) |  
| Публикувано | 05.02.06 12:02 |  
             |  
           | 
            
           
  Нещо неразбрах.. или ми се спи.. Знаеш кога е роден човека и незнаеш как да "изчислиш" колко време е минало до сега?
 Примерно:
 Роден 1950
 Сега сме 2006
 2006-1950 на колко беше равно....
  
           
  
             |   |  
           
             
               
               
                 
                   | 
                   Тема
                    | 
                     Re: изчисляване на възраст 
[re: Sanndo]
 | 
 
 |  
| Автор | 
Computer (непознат) |  
| Публикувано | 05.02.06 13:33 |  
             |  
           | 
            
           
  пича сигурно иска да разбере кага точно става на еди си колко години
  
           
  
             |   |  
           
             
               
               
                 
                   | 
                   Тема
                    | 
                     Re: изчисляване на възраст 
[re: pitasht]
 | 
 
 |  
| Автор | 
Viper X (just a snake...) |  
| Публикувано | 05.02.06 14:11 |  
             |  
           | 
            
           
  - $birthyear; $birthmonth; $birthday
 - $currentyear; $currentmonth; $currentday
 
 $age = $currentyear - $birthyear;
 if ($birthmonth > $currentmonth) $age--;
 if  (($birthmonth == $currentmonth) && ($birthday > $currentday)) $age--;
  
           
  
             |   |  
           
             | 
               
                |  
           | 
            
           
  <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. 
           
  
             |   |  
           
             
               
               
                 
                   | 
                   Тема
                    | 
                     Re: изчисляване на възраст 
[re: Chavdarov]
 | 
 
 |  
| Автор | 
Bълk (умора няма) |  
| Публикувано | 06.02.06 01:12 |  
             |  
           | 
            
           
  кхъм ... я пак с логическо уравнение .... пък и каква е връзката с високосната година?
  -----------------
 живей днес, защото вчера няма да се върне, а утре може и да не дойде!
           
  
             |   |  
           
             
               
               
                 
                   | 
                   Тема
                    | 
                     Re: изчисляване на възраст 
[re: Bълk]
 | 
 
 |  
| Автор | 
NetWalker (walker) |  
| Публикувано | 07.02.06 12:54 |  
             |  
           | 
            
           
  29 февруари - която и да е високосна година 
  *** *** ***
       
           
  
             |   |  
           
             
               
               
                 
                   | 
                   Тема
                    | 
                     Re: изчисляване на възраст 
[re: NetWalker]
 | 
 
 |  
| Автор | 
Bълk (умора няма) |  
| Публикувано | 07.02.06 14:44 |  
             |  
           | 
            
           
  (($nowmonth < $mage) OR (($nowmonth < $mage) AND ($lnowday < $dage)))
 
 мен това ме съмнява ... абсолютна глупост е
  -----------------
 живей днес, защото вчера няма да се върне, а утре може и да не дойде!
           
  
             |   |  
           
             
               
               
                 
                   | 
                   Тема
                    | 
                     Re: изчисляване на възраст 
[re: pitasht]
 | 
 
 |  
| Автор | aз (Нерегистриран) |  
| Публикувано | 07.02.06 19:18 |  
             |  
           | 
            
           
  <?php
 	$meseci = array("1"=>"31", "2"=>"28", "3"=>"31", "4"=>"30", "5"=>"31", "6"=>"30",
 			"7"=>"31", "8"=>"31", "9"=>"30", "10"=>"31", "11"=>"30", "12"=>"31");
 	
 	$year = 1976;
 	$month = 12;
 	$day = 28;
 
 	$cDay = date(d);
 	$cMonth = date(m);
 	$cYear = date(Y);
 	
 	if ($cDay < $day) {
 		$cDay = $cDay + $meseci[$month];
 		if ($cMonth == 1) {
 			$cMonth = 12;
 			--$cYear;
 		}
 		else {
 			--$cMonth;
 		};
 	};
 	$day = $cDay - $day;
 	
 	if ($cMonth < $month) {
 		$cMonth = $cMonth + 12;
 		--$cYear;
 	}
 	$month = $cMonth - $month;
 
 	$year = $cYear - $year;
 	
 	echo "Някой е на $year години, $month месеца и $day дни ;)";
 ?>
  
           
  
             |   |  
           
             
               
               
                 
                   | 
                   Тема
                    | 
                     Re: изчисляване на възраст
[re: pitasht]
 | 
 
 |  
| Автор | aз (Нерегистриран) |  
| Публикувано | 07.02.06 19:21 |  
             |  
           | 
            
           
 
 
 <?php
 	$meseci = array("1"=>"31", "2"=>"28", "3"=>"31", "4"=>"30", "5"=>"31", "6"=>"30",
 			"7"=>"31", "8"=>"31", "9"=>"30", "10"=>"31", "11"=>"30", "12"=>"31");
 	
 	$year = 1976;
 	$month = 12;
 	$day = 28;
 
 	$cDay = date(d);
 	$cMonth = date(m);
 	$cYear = date(Y);
 	
 	if ($cDay < $day) {
 		$cDay = $cDay + $meseci[$month];
 		if ($cMonth == 1) {
 			$cMonth = 12;
 			--$cYear;
 		}
 		else {
 			--$cMonth;
 		};
 	};
 	$day = $cDay - $day;
 	
 	if ($cMonth < $month) {
 		$cMonth = $cMonth + 12;
 		--$cYear;
 	}
 	$month = $cMonth - $month;
 
 	$year = $cYear - $year;
 	
 	echo "Някой е на $year години, $month месеца и $day дни ;)";
 ?> 
  
           
  
             |   |  
  |   
 
 
 |  
 |   
 |