Hi!
I wrote this simple function to return the current date minus supplied
number of years:
function get_birthdate($age_in_years) {
// get the current timestamp into an array
$timestamp = time();
$date_time_array = getdate($timestamp);
$hours = $date_time_array["hours"];
$minutes = $date_time_array["minutes"];
$seconds = $date_time_array["seconds"];
$month = $date_time_array["mon"];
$day = $date_time_array["mday"];
$year = $date_time_array["year"];
// use mktime to recreate the unix timestamp
// subtracting age_low and age_high from the years
$timestamp = mktime($hours, $minutes,$seconds ,$month, $day,$year -
$age_in_years);
$birthdate = strftime("%d/%m/%Y", $timestamp);
return($birthdate);
}
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?
Sincerely,
Nicklas
--
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]