RE: [PHP] Unix-time problem

From: Date: Mon, 05 Mar 2001 03:51:41 +0000
Subject: RE: [PHP] Unix-time problem
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-42566@lists.php.net to get a copy of this message
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 dread@texas.net -- If you are going to sin, sin against God, not the bureaucracy. God will forgive you but the bureaucrats won't.

« previous php.general (#42566) next »