RE: difference between two dates

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

 



> 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/



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux