On Nov 28, 2007 7:44 AM, Paul Allen <[EMAIL PROTECTED]> wrote:

> jagdish eashwar wrote:
> > Hi,
> > I want to subtract one date from another. I read in the documentation:
> >
> > "If you only care about the date (calendar) portion of a datetime, you
> > should use either delta_md() or delta_days(), not subtract_datetime().
> This
> > will give predictable, unsurprising results, free from DST-related
> > complications."
> > What is the exact syntax for using delta_days()?
> >
> It is difficult to answer a question like this without sounding
> condescending or
> judgemental.  The problem, of course, is that the answer to your question
> is
> right there in the perldoc for DateTime along with the text you quoted.
> To find
> the answer, simply say "perldoc DateTime" and search for the first
> occurrence
> of "delta_days".  If you are not sure how to use perldoc, say "perldoc
> perldoc".
> Note that perldoc uses a pager from the underlying platform, and you use
> the
> search facilities of this pager to find things in a document.
>
> Good luck.
>
> Paul Allen


Hi Paul,

Thanks a lot for being gentle with me. I did go through the documentation
and tried several permutations and combinations, but I couldn't get the
syntax right. After your response, I went over my trials again and came up
with nothing. Here is my script:

#!/usr/bin/perl
use strict;
use warnings;

use DateTime;

my $date1 = DateTime->new(year => 2007,
             month => 2,
             day => 2);
my $date2 = DateTime->new(year => 2007,
             month => 1,
             day => 1);

my $dur = $date1-$date2;

print $dur,"\n";
# This gives me ---------- "DateTime::Duration=HASH(0x83b3050)"

print $dur->days,"\n";
# This gives me --------- "1"

$dur = $date1->delta_days($date2);
print $dur,"\n";
# That gives me ------------- "DateTime::Duration=HASH(0x8386fa8)"

print $dur->days,"\n";
# This gives me --------- "4"

$dur = delta_days($date1);

print $dur,"\n";
# This gives me ---------- "Undefined subroutine &main::delta_days called at
./datetime.plx line 30."

Can you please tell me what I am doing wrong?

jagdish

Reply via email to