I must not understand how subtraction works with DateTime. Using one method, I get 4 days and using another, apparently equivalent, method, I get 5 days duration:
main::(a.pl:49): my $first_time_date_time=DateTime::Format::ISO8601 +->parse_datetime($first_time); + + DB<2> p $first_time 2013-08-01T20:10:31 + + DB<3> n main::(a.pl:50): my $last_time_date_time=DateTime::Format::ISO8601- +>parse_datetime($last_time); + + DB<3> p $last_time 2013-08-06T20:09:34 + + DB<4> n main::(a.pl:51): my $duration=$last_time_date_time->subtract_dateti +me($first_time_date_time); + + DB<4> main::(a.pl:52): my $days=$duration->days; + + DB<4> p $duration DateTime::Duration=HASH(0x1a2f268) + + DB<5> p $duration->in_units('days') 4 + + DB<6> x $duration->deltas() 0 'months' 1 0 2 'days' 3 4 4 'minutes' 5 1439 6 'seconds' 7 3 8 'nanoseconds' 9 0 + + DB<7> $d=$last_time_date_time->delta_days($first_ +time_date_time) + + DB<8> p $d DateTime::Duration=HASH(0x1e1e2e8) + + DB<9> p $d->in_units('days') 5

In reply to Inconsistent results of subtraction with DateTime? by jabowery

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.