NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.
All the Perl that's Practical to Extract and Report
Stories, comments, journals, and other submissions on use Perl; are Copyright 1998-2006, their respective owners.
DateTime::Duration does not DWIM (Score:1)
You might want to consider something along these lines.
use strict;
use warnings;
use DateTime;
use DateTime::Format::Duration;
use Data::Dumper;
my $dt1 = DateTime->now(
time_zone => 'UTC',
);
my $dt2 = DateTime->new(
year => 2006,
month => 10,
day => 31,
time_zone =>'UTC',
);
my $delta = $dt1->delta_ms($dt2);
print Dumper($delta), "\n";
my $d = DateTime::Format::Duration->new(
pattern => '%M minutes'
);
print $d->format_duration($delta);
Here I used the delta_ms method (see the docs) to create the duration. Also don't forget to use the format_duration method for getting at the value of minutes
I hope this helps.
Reply to This