How do I find a date which is three days earlier than a given date in Perl?

date, perl

Solution

`Date::Calc` is the champion module here:

use strict;
use warnings;
use Date::Calc qw(Add_Delta_YMD);

my $startDate = '2000-01-01';
my ($startYear, $startMonth, $startDay) = $startDate =~ m/(\d{4}-(\d{2})-\d{2})/;

# 1 year, 2 months, 3 days, after startDate
my $endDate = join('-', Add_Delta_YMD($startYear, $startMonth, $startDay, 1, 2, 3));

The module has a huge number of time conversion routines, particularly those dealing with deltas. `DateTime` and `Date::Manip` are also worth checking out.

Problem

How do I find a date which is 3 days earlier than a given date in Perl where the format is YYYY-MM-DD?

Original source