Mr. Shawn H. Corey wrote:
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>
perldoc Time::Local
[ snip ]
Limits of time_t
The range of dates that can be actually be handled depends on the
size of "time_t" (usually a signed integer) on the given platform.
Currently, this is 32 bits for most systems, yielding an approximate
range from Dec 1901 to Jan 2038.
^^^^^^^^ ^^^^^^^^
John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order. -- Larry Wall
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/