in reply to Add A Number of Days to Today's Date
Perl finds it all much easier if you deal with dates as the number of seconds since 00:00 Jan 1 1970 (this number, incidently, has just passed one billion). The function time gives this value for the current time and the timelocal function (from the Time::Local module) can convert any date or time into this format.
You can then use the POSIX::strftime to convert that value into a human-readable string. Here's an example:
use POSIX 'strftime'; my $now = time; my $then = $now + (20 * 86_400); # 86,400 seconds in a day my $then_str = strftime('%d %B %Y', localtime($then)); print "In 20 days time it will be $then_str\n";
Of course, it's possible to write that more compactly :)
--use POSIX 'strftime'; print "In 20 days time it will be ", strftime('%d %B %Y', localtime(time + 20 * 86_400)), "\n";
"The first rule of Perl club is you don't talk about Perl club."
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Add A Number of Days to Today's Date
by rline (Initiate) on Sep 29, 2001 at 04:55 UTC |