?
Solved

Age

Posted on 2003-03-24
2
Medium Priority
?
137 Views
Last Modified: 2010-03-05
Let4s say I4ve got a birthday from a person stored in an variable called $Bdate. for example:
$Bdate="31-08-1975";
How can I calculate how old this person is ?
0
Comment
Question by:michael123199
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 10

Accepted Solution

by:
rj2 earned 100 total points
ID: 8196221
#!/usr/bin/perl
$Bdate="31-08-1975";
if($Bdate =~ m/(\d+)-(\d+)-(\d+)/) {
     ($d,$m,$y)=($1,$2,$3);
     ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
     if($m*100+$d < ($mon+1)*100+$mday) {
          $add=1;
     }
     $age=$year+1900-$y+$add-1;
     print "Age: $age years\n";
}    

0
 
LVL 26

Expert Comment

by:wilcoxon
ID: 8197207
If you want to do anything more advanced with dates or can't guarantee the format, you should look into Date::Calc (fast) or Date::Manip (slower but does just about anything you might want to do with dates).
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question