Jump to content

Finding Age from Birthdate


evil_stevo

Recommended Posts

//calculate age
$birthdate = "1978-04-26"; //birth date... actually being obtained from a database
$today = date("Y-m-d H:i:s"); // The exact date
$age = date_diff($str_birthday, $today);

echo $age;

 

I'd like a simple code to echo the age of someone with the mysql database information that's in their record. This doesn't work. I have no idea why. Nothing seems to work that I've found on the net. Please help. Thanks.

Link to comment
Share on other sites

Perhaps...

 

<?php
$dob = "1978-04-26";
$ageTime = strtotime($dob); // Get the person's birthday timestamp
$t = time(); // Store current time for consistency
$age = ($ageTime < 0) ? ( $t + ($ageTime * -1) ) : $t - $ageTime;$year = 60 * 60 * 24 * 365;
$ageYears = $age / $year;
?>

Link to comment
Share on other sites

That worked great litebearer!!! I did a little modification for my own and got rid of the decimal and this came out...

 

$birthdate = "1985-07-15";

//calculate age
$ageTime = strtotime($birthdate); // Birthday Timestamp
$t = time(); // Current Time
$age = ($ageTime < 0) ? ( $t + ($ageTime * -1) ) : $t - $ageTime;$year = 60 * 60 * 24 * 365;
$ageYears = $age / $year;
$age = number_format($ageYears,0); //Delete Decimals

echo $age;

 

Let me know what you think... THANKS AGAIN! IT WAS JUST THE TICKET!!!! :) :) :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.