Calculate the age using data from my database

前端 未结 3 1506
执念已碎
执念已碎 2021-01-24 22:41

This is the code I\'m currently using, but it\'s not working. Geboortedatum means day of birth in Dutch.

mysql_connect(\'xxx\', \'xxx\', \'xxx\');

mysql_select_         


        
3条回答
  •  佛祖请我去吃肉
    2021-01-24 23:33

    Here's an approach if you want a breakdown by years, months, and Days:

    $secondsInAYear     = 31536000;
    $secondsInAMonth    =  2635200; //Using the average (30.5) days in a month.
    $secondsInADay      =    86400;
    
    
    echo $datum;
    $birthDate = strtotime($datum);
    
    $ageInSeconds   = time() - $birthDate;
    
    $ageInYears = floor( $ageInSeconds / $secondsInAYear );
    $ageRemainder   = ( $ageInSeconds % $secondsInAYear );          // $a % $b  [ Modulus:  Remainder of $a divided by $b ]     
    
    $ageInMonths    = floor( $ageRemainder / $secondsInAMonth );
    $monthsRemainder    = ( $ageRemainder % $secondsInAMonth );
    
    $ageInDays      = floor( $monthsRemainder / $secondsInAMonth );    
    
    echo "Age is:" .$ageInYears ." Years, " .$ageInMonths ." Months, and " .$ageInDays ." Days.;
    

提交回复
热议问题