|
Posted by Edward Vermillion on 07/07/05 06:57
On Jul 6, 2005, at 5:31 PM, Edward Vermillion wrote:
>
> On Jul 6, 2005, at 5:17 PM, Edward Vermillion wrote:
>
>>
>> On Jul 6, 2005, at 4:44 PM, Philip Hallstrom wrote:
>>
>>>> of leap years between the two dates. Leap years occur every 4
>>>> years, and 17 / 4 = 4.25, so there were 4 leap years between 7/6/88
>>>> and 7/6/05 and
>>>
>>> Just to nitpick... :-)
>>>
>>> http://en.wikipedia.org/wiki/Leap_year
>>>
>>> The Gregorian calendar adds an extra day to February, making it 29
>>> days long, in years where the quotient has no remainder when divided
>>> by 4, excluding years where the quotient has no remainder when
>>> divided by 100, but including years where the quotient has no
>>> remainder when divided by 400. So 1996, 2000, and 2400 are leap
>>> years but 1800, 1899, 1900 and 2100 are not.
>>>
>>> --
>>> PHP General Mailing List (http://www.php.net/)
>>> To unsubscribe, visit: http://www.php.net/unsub.php
>>>
>>>
>>
>> I always wondered what kind of drugs those guys were on when they
>> came up with the leap-year system... :P
>>
>> One interesting side note to the op's problem, since I'm not going to
>> be able to do anything else till I figure this out now..., if one of
>> the dates is a leap year the 365.25 works fine, which make me wonder
>> how the strtotime() function is working... or maybe that's what it's
>> supposed to do... ;)
>
> But then, even if I do figure this out, it's still going to tell me
> I'm only 35... which is a bit off...
>
> As usual Richard's way is probably the best for any "real world" age
> deduction. ;)
Well, I'll let you test through it but it seems to work with the two or
three dates I ran through...
<?php
$bd="1988-07-07"; // birth date
$td="2005-07-06"; // today
$day1 = strtotime($bd);
$day2 = strtotime($td);
$sy = 31536000; // short year 365 days
$spd = 86400; // seconds per day
$realAge = floor(($day2-$day1-($spd*floor((($day2 -
$day1)/$sy)/4)))/$sy);
print $realAge;
exit;
?>
I left $sy and $spd in so you could see where those values were coming
from
but you could just as well stick the numbers in for the vars and only
have $day1
and $day2 hanging around.
of course it only works on most systems with "birth dates" before the
epoch... :P
Edward Vermillion
evermillion@doggydoo.net
Navigation:
[Reply to this message]
|