Re: difference in absolute days

[email protected] ("Perrin Harkins")
Newsgroups perl.datetime
Message-ID <[email protected]>
On Mon, Dec 15, 2008 at 8:29 PM, Alex Teslik <[email protected]> wrote:
> On Mon, 15 Dec 2008 20:04:26 -0500, Perrin Harkins wrote
>
>> my $d1 = DateTime->today;
>> my $d2 = $d1->clone->subtract(years => 1);
>>
>> my $dur = $d1->delta_days($d2);
>> print $dur->in_units('days') . "\n";
>>
>
> corrected above. I don't know why the days method didn't work.

Thanks Alex.  That does what I want.

Previously I was trying to make this work with overloaded subtraction
instead of delta_days():

my $dur = $d1 - $d2;

The object returned here gives '0' for days() and in_units('days') and
'1' for years().  I think that's by design, but something seems off
here, and my guess is that it's the return of days() on the
delta_days() Duration object (which gives me '2').

- Perrin
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.