Jump to content

[SOLVED] Subtract dates to get age


SkyRanger

Recommended Posts

I am trying to figure out how to get a visitors age from the date they submitted.

 

I tried a number of things which either a: didn't work or b: had so much code it confused the heck out of me and still didn't work.

 

I tried things like:

 

$bdate = March 31 1972

$age = date('F d Y') - $bdate 

 

Tried breaking them down into different parts, but that still didn't work, any help would be greatly apprectiated.

 

So what I am trying todo is say subtract bdate from todays date so for example it would say Age: 35

 

Or if the bday was May 24 1972 then the age would say Age: 34

 

Any help would be greatly appreciated.

 

Link to comment
https://forums.phpfreaks.com/topic/49203-solved-subtract-dates-to-get-age/
Share on other sites

Awsome, thanks barand,figured it out.

 

           $birthyear = $rowpref['byear'];
   $birthday = $rowpref['bday'];
   $birthmonth = $rowpref['bmonth'];
   
$year_diff = date("Y") - $birthyear;
        $month_diff = date("m") - $birthmonth;
        $day_diff = date("d") - $birthday;
            if ($month_diff < 0)
               $year_diff--;
            elseif ($month_diff == 0 && $day_diff < 0)
               $year_diff--;
  
echo $year_diff;

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.