in reply to Subtracting Dates
I really don't understand why people insist on reaching for Date::Foo modules so quickly. Both Date::Calc and (especially) Date::Manip are overkill for this problem.
To get the time two weeks ago, simply subtract the relevant number of seconds from the current time. You can then convert that into a human-readable value using localtime or (even easier) POSIX::strftime.
use POSIX 'strftime'; my $then = time - (14 * 24 * 60 * 60); my $date = strftime ('%Y%m%d', localtime $then); print $date; # prints 20020524
You can easily change the format of the date returned by changing the format string passed to strftime.
If you simply must use a CPAN module, then take a look at Time::Piece.
--use Time::Piece; use Time::Seconds; my $now = localtime; # Now a Time::Piece object my $then = $now - (14 * ONE_DAY); print $then->ymd; # or various other output functions
"The first rule of Perl club is you do not talk about
Perl club."
-- Chip Salzenberg
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Subtracting Dates
by Abigail-II (Bishop) on Jun 07, 2002 at 16:12 UTC | |
|
Re: Re: Subtracting Dates
by IlyaM (Parson) on Jun 07, 2002 at 17:16 UTC | |
|
Re: Re: Subtracting Dates
by joealba (Hermit) on Jun 07, 2002 at 17:17 UTC | |
by dsheroh (Monsignor) on Jun 07, 2002 at 17:55 UTC |