On Sat, 2008-09-20 at 03:53 -0700, John W. Krahn wrote:
> itshardtogetone wrote:
> > Hi,
> 
> Hello,
> 
> > How do I randomly produce a date between 1st Jan 1960 to 31th December
> > 1985. It must be able to show the day month year.
> > I only know how to produce a random number between 1960 to 1985 using
> > rand like this :
> > 
> > my $year = int (rand 26) + 1960;
> 
> use Time::Local;
> 
> my $start = timegm 0,0,0,1,0,60;
> my $end   = timegm 0,0,0,1,0,86;
> 
> print scalar gmtime $start + rand $end - $start;

Time::Local only works for dates between Jan. 1, 1959 and Dec. 31, 2038.
For dates outside of this range, use the DateTime module from CPAN
<http://search.cpan.org/author/DROLSKY/DateTime-0.4304/lib/DateTime.pm>


-- 
Just my 0.00000002 million dollars worth,
  Shawn

"Where there's duct tape, there's hope."
        Cross Time Cafe

"Perl is the duct tape of the Internet."
        Hassan Schroeder, Sun's first webmaster

"There is more than one way to do things."
        A Perl axiom


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to