You are here: Re: x years old « PHP « IT news, forums, messages
Re: x years old

Posted by Jasper Bryant-Greene on 07/03/05 03:06

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

 

Navigation:

[Reply to this 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

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