|
Posted by Justin Koivisto on 01/30/06 22:19
comp.lang.php wrote:
> Please go over this line by line, you completely lost me.
>
> Phil
>
> Kim André Akerø wrote:
>> comp.lang.php wrote:
>>
>>> Dangit I thought I could do THIS simple task today and even this is
>>> beyond me!! :(
>>>
>>> [code]
>>> <?= date(time()) - date(strtotime($result[0]->birth)) ?>
>>> [/code]
>>>
>>> This is completely wrong, but what IS right? I'm stumped!
>> More like this:
>> http://james.cridland.net/code/age.html
>>
>> In your case, the code would be:
>>
>> <?php
>>
>> $birthdate = strtotime($result[0]->birth);
unix timestamp of birth date (midnight if no time is included) - if on
windows server & date is before 1970, the value will be "-1" - nothing
that you can really use.
>> $age = date("Y") - date("Y",$birthdate);
The current 4-digit year minus the 4 digit birth year (assuming that the
strtotime call worked)
>> if ((date("n") < date("n",$birthdate)) or ((date("n") ==
>> date("n",$birthdate)) and (date("j") < date("j",$birthdate)))) {
if (
numeric month of now < numeric month of birth date
or
numeric month of now == numeric month of birth date
and
day of month now < day of month birth date
>> $age--;
Take off a year because they haven't hit their birthday of this year yet
>> }
>>
>> echo $age;
The number of years old they are
--
Justin Koivisto, ZCE - justin@koivi.com
http://koivi.com
Navigation:
[Reply to this message]
|