Age

Petit script en PHP, au demeurant sympathique, qui vous permet d'afficher et de mettre à jour automatiquement votre age sur une page web.

 <?php
 #
 # age.php - v1.0 par orx57
 # [ http://www.orx57.net ]
 #
 # Vous n'avez qu'à renseigner les trois
 # variables suivantes, au noms très parlants,
 # et à ajouter l'instruction include à l'endroit
 # où vous souhaitait voir apparaître votre age :
 #
 #       include("age.php");
 #

 $myBirthDay = 23;
 $myBirthMonth = 11;
 $myBirthYear = 1980;
 #################################################

 $current_date = getdate(time());

 $birthday_date = getdate(mktime(0,0,0,$myBirthMonth,$myBirthDay,$myBirthYear));

 if ( $current_date["mon"] < $birthday_date["mon"] )
     $age = $current_date["year"] - $birthday_date["year"] - 1 ;

 if ( $current_date["mon"] > $birthday_date["mon"]  )
     $age = $current_date["year"] -  $birthday_date["year"] ;

 if ( ( $current_date["mon"] == $birthday_date["mon"] ) && 
     ( $current_date["mday"] <  $birthday_date["mday"] ) )
     $age = $current_date["year"] - $birthday_date["year"] - 1 ;

 if ( ( $current_date["mon"] == $birthday_date["mon"] ) &&
     ( $current_date["mday"] >= $birthday_date["mday"] ) )
     $age = $current_date["year"] - $birthday_date["year"] ;

 printf ("%d\n" , $age);
 ?>