Hi, Having some trouble with Perl's DateTime package -- essentially trying to periodically query a MySQL db for the nearest time stamp and compare it with the current time, to see how much time there is before the next "event". The correct record is chosen via the SQL query, so no worries there. Here's the date comparison code:

my $now = DateTime->now(time_zone => 'America/New_York'); my $then = DateTime::Format::MySQL->parse_datetime($last); print "NOW: "; print $now; print "\n"; print "THEN: "; print $then; print "\n"; my $diff = $then->delta_ms($now); print "\n"; print $diff->in_units('minutes'); print "\n";

...where the $last var corresponds to the MySQL record's datetime format. The conversion to Perl's DateTime object seems to go ok, as can be seen by this output..

[root@localhost directory]# ./sql-test.pl SQL: 2009-10-06 18:00:00 NOW: 2009-10-05T14:48:09 THEN: 2009-10-06T18:00:00 191

But the problem is that I want to compare the diff in minutes, and as can be seen above, the day is ignored in the comparison. yes, there are more than just minutes in the diff, but between the delta_ms and in_minutes calls the larger time blocks should be converted to minutes. Any idea what's going on here, I'm banging my head against the keyboard... ...thanks.


In reply to SOLVED: DateTime question by antigua

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.