Dear Monks,
I need to compute duration intervals from various dates. I read through the DateTime Tutorial on perlmonks and choose to use this module. Unfortunately, i'm getting strange results on a first test : misunderstanding or bug ?
here is the code :
use strict;
use warnings;
use DateTime;
my $t1 = DateTime->new(year => 2001,
month => 4,
day => 23,
hour => 22,
minute => 32);
my $t2 = DateTime->new(year => 2001,
month => 4,
day => 22,
hour => 15,
minute => 42);
print "T1 = ".$t1->hour.":".$t1->minute."\n
T2 = ".$t2->hour.":".$t2->minute."\n
T1-T2 = ".$t1->subtract_datetime($t2)->hours."\n
T2-T1 = ".$t2->subtract_datetime($t1)->hours."\n";
Here is the result :
T1 = 22:32
T2 = 15:42
T1-T2 = 6
T2-T1 = 6
Any comment or help would be appreciated, or if you know a better module to do that (i'll need to compute duration intervals in term of days also, which implies knowing the month's lengh ...)
Thanks,
Marcel
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.