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:
Taking Away Dates to get Age

 



benchivers
Novice

Aug 4, 2002, 11:54 PM

Post #1 of 3 (315 views)
Taking Away Dates to get Age Can't Post

I have made a signup script using PERL and it asks for the user's date of birth in the form MM/DD/YYYY

Is there any way of reading the current date using 'localtime()' to take away the user's date of birth to get their age? Their age must be exact as well.

Any help would be most appreciated

Many Regards,

Ben Chivers
Wheres the damn coffee? zzzZZZZZ!!!


davorg
Thaumaturge / Moderator

Aug 5, 2002, 1:48 AM

Post #2 of 3 (315 views)
Re: [benchivers] Taking Away Dates to get Age [In reply to] Can't Post

Here's a script that I wrote to calculate the difference in days between a given date (in the format YYYYMMDD) and the current date. You might be able to reuse parts of that.

Code
#!/usr/bin/perl -w 

use strict;
use Time::Local;

my $then = shift || die "Wrong!!\n";

my @then = $then =~ /(\d\d\d\d)(\d\d)(\d\d)/;

die "Badness\n" unless @then == 3;

$then[0] -= 1900;
$then[1]--;

$then = timelocal(0, 0, 0, @then[2,1,0]);

my $diff = ($then - time) / 86_400;
my $neg = int($diff) < 0;
$diff = abs $diff;

print $neg ? '-' : '', int ($diff + .5), " day(s)\n";


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


benchivers
Novice

Aug 8, 2002, 11:20 AM

Post #3 of 3 (302 views)
Re: [davorg] Taking Away Dates to get Age [In reply to] Can't Post

Thanks for the reply Dave, it's hepled!

Looks like we both have something in common, I was born in Colchester too, and still live there of course!



Many Regards,

Ben Chivers
Wheres the damn coffee? zzzZZZZZ!!!

 
 


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

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