[Subject Prev][Subject Next][Thread Prev][Thread Next][Subject Index][Thread Index]
Re: Calculate age from DOB in perl
On Wed, 24 Jan 2001, Adityan Murthy wrote:
> Hi all,
> How do i calculate the current age of a person using his DOB? I am not
> using any database.
Hi, the following code would do what u want.
$No_Of_Secs_In_A_Day = 24 * 60 * 60;
$No_Of_Days_In_A_Year = 365;
$DOB = '29/05/1980';
($Day, $Month, $Year) = split(/\D/, $DOB);
$DOB_Time = timelocal($Secs, $Mins, $Hours, $Day, ($Month-1), $Year);
$Age = time() - $DOB_Time;
$Age = int($Age/$No_Of_Secs_In_A_Day);
$Age = int($Age/$No_Of_Days_In_A_Year);
print "Person born on $DOB must be $Age yrs. today !\n";