in reply to Best way to compare date strings

Use the DateTime family of modules.

#!/usr/bin/perl use strict; use warnings; use DateTime::Format::Strptime; my $fmt = DateTime::Format::Strptime->new(pattern => '%Y/%m/%d %H:%M:% +S:%3N'); my $date1 = $fmt->parse_datetime('2006/01/03 03:59:59:671'); my $date2 = $fmt->parse_datetime('2006/01/03 04:00:00:562'); my $diff = $date2 - $date1; print $diff->in_units('nanoseconds'), "\n";
--
<http://dave.org.uk>

"The first rule of Perl club is you do not talk about Perl club."
-- Chip Salzenberg

Replies are listed 'Best First'.
Re^2: Best way to compare date strings
by minixman (Beadle) on Jan 04, 2006 at 12:36 UTC
    Strange when i install the mods and run i get.
    $ perl test.pl Can't call method "in_units" on an undefined value at test.pl line 22.
      I downloaed the modules again and installed them, still get strange errors
      $ perl test.pl Scalar found where operator expected at (eval 4) line 1, near "%+$nano +second" (Missing operator before $nanosecond?) syntax error at (eval 4) line 1, near "%+$nanosecond"

        It looks like you might have cut and pasted the code from your browser instead of using the 'download' link. That will add extra '+' characters into the code where it get split on a line break.

        --
        <http://dave.org.uk>

        "The first rule of Perl club is you do not talk about Perl club."
        -- Chip Salzenberg