Offsetting dates from the past in Date::Manip

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I'm trying to use Date::Manip to resolve strings which represent dates
according to a known reference point - e.g. given a known date, what
does "Friday" represent?. If I do something like this:

my $date = ParseDate("Friday");
print $date;

I get the result I expect, i.e. 13/06/08 (assuming I changed the
format to DD/MM/YY). However, the date used for as the reference point
is always the current date, and I want to be able to put in an
arbitrary date and have the reference resolved from there. For
example, if I use this time last year, "Friday" should be resolved to
a different date - 15/06/07. Does anyone know if it is possible to do
this within Date::Manip? I've tried using DateCalc, but this gives me
an offset from the current date, which isn't really what I want.

Thanks in advance,


P.S. I'm only dealing with recent dates (1990-present), so there
shouldn't be any problems with pre-1900 dates etc.

Re: Offsetting dates from the past in Date::Manip

Quoted text here. Click to load it

yes, I know you were asking about Date::Manip, but a solution using
Date::Calc is:

use strict;
use warnings;
use Date::Calc qw ( :all );
my @today = Today();
my @year_ago = Add_Delta_YM( Today(), -1, 0 );
my $that_day = Day_of_Week(@year_ago[0..2]);
my $day_reference = 5;  # Friday is day 5 of week
my $days_until_reference = ($day_reference - $that_day + 7) % 7;
my @friday_a_year_ago = Add_Delta_YMD( @year_ago, 0, 0,

print Date_to_Text( @friday_a_year_ago[0..2] );

Site Timeline