RE: [PHP-DB] difference between two dates
| From: | John W. Holmes | Date: | Sun, 19 Jan 2003 14:34:02 +0000 |
| Subject: | RE: [PHP-DB] difference between two dates | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-24947@lists.php.net to get a copy of this message | ||
> In my application I am accepting Day, Month and Year from a Select
List.
> What I want to do is calculate the age of the person based on the
above
> selection.
>
> $cboDD is the day variable
> $cboMM is the month variable
> $cboYY is the year variable
>
> I tried this :
>
> $dobtimestamp = mktime(0,0,0,$cboMM,$cboDD,$cboYY);
> $todaytimestamp = time();
> $txtAge = ($todaytimestamp - $dobtimestamp)/86400;
>
> It does not give me the expected output.
>
> Can anybody suggest something ?
Keep your mktime() as it is, that's correct. Then use something like
this to calculate the age:
$age = date('Y',$now) - date('Y',$dob) -
((date('z',$now)>=date('z',$dob)) ? 0 : 1);
where $dob and $now are the appropriate unix timestamps that you've
already got calculated with mktime() and time().
---John W. Holmes...
PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/