Re: Re: x years old

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



and for completeness of the topic, ceil() will round fractions up.
i.e. 

ceil(16.00001) = 17
ceil(16.00000) = 16

<attempted-humor>
I think the Credit Card Industry using ceil() alot ;P
</attempted-humor>

On 7/2/05, Jasper Bryant-Greene <jasper@xxxxxxxxxxxxxxxxxx> wrote:
> 
> Ryan A wrote:
> > Hey guys,
> > This is the code I am using to display a persons age from the mysql db:
> >
> > $day1=strtotime($age);
> > $day2 = strtotime(date("Y-m-d"));
> > $dif_s = ($day2-$day1);
> > $dif_d = ($dif_s/60/60/24);
> > $age = round(($dif_d/365.24));
> >
> > but when someone entered their birth day($age) as 1988-07-06 it is 
> showing
> > it as
> > 17 years old instead of 16...any idea whats wrong in the above code?
> 
> Use floor() instead of round(). Using the round() function will round
> anyone whose age is above 16.5 to 17, while floor() always rounds down.
> 
> Jasper
> 
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
>

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux