Finding age by date

By X-FILE on Sep 03, 2004

The name says it all. You can find the age of the person by his birthday.
The idea was not mine , I have seen something like this in another language and thought It would be nice to make it in php. Example on how to use :

use this :
print agebydate(06, 6, 1990);

And it will display 14 (2004-1990) .

NOTE : Negative timestamps (mktime()) are not supported under any known version of Windows.

Therefore this means valid years include only 1970 through 2038.

<?php 
function agebydate($iMonth, $iDay, $iYear) { 
    $iTimeStamp = (mktime() - 86400) - mktime(0, 0, 0, $iMonth, $iDay, $iYear); 
    $iDays = $iTimeStamp / 86400;  
    $iYears = floor($iDays / 365 );  1
    return $iYears; 

} 

?> 

1. floor Returns the  lowest integer value. 

Comments

Sign in to comment.
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.