CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Age check

 



cypher_MS
Novice

Aug 26, 2002, 5:30 PM

Post #1 of 3 (510 views)
Age check Can't Post

ok, how would I check someones birthday to see if they were older than thirteen? the $FORM{'bday'} is in the format MMDDYYYY..

Thanks
---
C:\Dos
C:\Dos\Run
Run Dos Run
---


thebitch
User

Aug 26, 2002, 11:45 PM

Post #2 of 3 (508 views)
Re: [cypher_MS] Age check [In reply to] Can't Post

You need to use one of the Date modules on cpan,
like Date::Calc .

You need recipee 3,
How do I verify whether someone has a certain age?
http://search.cpan.org/author/STBEY/Date-Calc-5.0/Calc.pod#RECIPES


davorg
Thaumaturge / Moderator

Aug 27, 2002, 1:17 AM

Post #3 of 3 (506 views)
Re: [cypher_MS] Age check [In reply to] Can't Post

I like Time::Piece and Time::Seconds for this kind of calculation. They really make working with dates and times very simple.

Code
#!/usr/bin/perl -w 

use strict;

use Time::Piece;
use Time::Seconds;

my $today = localtime;

while (<DATA>) {
chomp;

my $bday = Time::Piece->strptime($_, '%m%d%Y');

my $diff = $today - $bday;

print "$_ - ", ($diff < 13 * ONE_YEAR) ? 'no' : 'yes', "\n";
}

__END__
08251989
08261989
08271989
08281989
08291989
08301989


--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives