On 05-Mar-01 Nicklas af Ekenstam wrote:
> Hi!
> 
> I wrote this simple function to return the current date minus supplied 
> number of years:
> 
> function get_birthdate($age_in_years) {
>       
<snip>

> You, obviously, call it like this: echo get_birthdate(1);
> Which would return a datestring that looks like this: 05/03/2000
> 
> Works nice, but the problem occurs when I try to subtract more than 31 
> years which is naturall since, as far as UNIX is concerned, the world 
> didn't exist then.
> (Took me a while to figure this one out though.)
> 
> Any clues on how to fix this so that I can go beyond the past 31 years?
> 

function get_birthdate($age_in_years) {
  list ($y,$m,$d) =explode('-', date('Y-m-d'));
  $bdstr=sprintf("%02d/%02d/%04d", $m, $d, $y - $age_in_years);
  return($bdstr);
}

Regards,
-- 
Don Read                                         [EMAIL PROTECTED]
-- If you are going to sin, sin against God, not the bureaucracy. 
                  God will forgive you but the bureaucrats won't. 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to