http://www.perlmonks.org?node_id=799319

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

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.