Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

A DateTime penance has befallen me

by jfrm (Monk)
on Oct 22, 2007 at 17:52 UTC ( #646521=perlquestion: print w/replies, xml ) Need Help??

jfrm has asked for the wisdom of the Perl Monks concerning the following question:

Normally by re-reading the documentation repeatedly, eventually, I get it. But not this time.
my $startdt = DateTime->new(day => 1, month => 4, year => 2007); my $enddt = DateTime->new(day => 22, month => 10, year => 2007); my $duration = $startdt->delta_days($enddt); my $numdays = $duration->days; print "Test: Number of days in period :$numdays (".$startdt->dmy('/'). +" - ".$enddt->dmy('/').")<Br>";

Result

Test: Number of days in period :1 (01/04/2007 - 22/10/2007)

Can anyone enlighten (if you'll excuse me using the term so thoughtlessly in a temple) me as to how I might get the correct duration in days and why this result is only 1?

Replies are listed 'Best First'.
Re: A DateTime penance has befallen me
by ikegami (Patriarch) on Oct 22, 2007 at 18:08 UTC

    I suspect $duration->days() returns the *portion* of the duration that is measured in days. I think you want $duration->in_units('days').

Re: A DateTime penance has befallen me (weeks)
by tye (Sage) on Oct 22, 2007 at 18:08 UTC

    I didn't read any documentation but 204 days is 29 weeks and 1 day.

    - tye        

Re: A DateTime penance has befallen me
by Krambambuli (Curate) on Oct 22, 2007 at 19:33 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://646521]
Approved by ikegami
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2022-05-29 12:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you prefer to work remotely?



    Results (101 votes). Check out past polls.

    Notices?