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
In reply to Re: Subtracting Dates
by davorg
in thread Subtracting Dates
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |