Reply to Re: How do you get someone's age from DOB?

Your name:

Reply:


Posted by comp.lang.php on 01/30/06 22:28

Tried that, always came back with "1" every time, regardless of DOB
and/or current time.

Phil

Justin Koivisto wrote:
> 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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация