In my perl program, I am calculating warranty start date from warranty end date The difference is 3 years. Following is the chunk of code that I have written so far:
use Time::ParseDate;
use DateTime;
use POSIX;
use DateTime::Duration;
my $warranty_expiration_string = "20-May-07";
my $epoch = parsedate($warranty_expiration_string);
my $warranty_expiration = strftime "%D", localtime($epoch); # returns: 05/20/07
How do I deduct 3 years from $warranty_expiration to get $warranty_start date?
I tried,
$warranty_start->subtract(DateTime::Duration->new('years' => 3));
..but it did not work.
I don’t understand all the different date/time modules being mixed. You only need some of them, not all of them. If you want to do date math using DateTime anyway, you want something like this:
Most of the DateTime::Format::* modules are meant to be used with DateTime and I prefer to use those if I can.
You may also want to read more about the ongoing DateTime project and the list of recommended modules at: