in reply to Comparing dates in Perl

use strict; use warnings; use feature qw( say ); use DateTime qw( ); use DateTime::Format::Strptime qw( ); my $format = DateTime::Format::Strptime->new( pattern => '%d-%m-%Y', time_zone => 'local', on_error => 'croak', ); my $target = $format->parse_datetime('05-08-2012'); my $today = DateTime->today( time_zone => 'local' ); say $today->delta_days($target)->in_units('days'); # 123

Replies are listed 'Best First'.
Re^2: Comparing dates in Perl
by locked_user sundialsvc4 (Abbot) on Apr 04, 2012 at 21:39 UTC

    ++

    Most of the time, I find myself coming back to this module because it’s an abstract data type.   An instance of the object, once loaded with a particular date by whatever means, “is an” instance of that date.   It is completely opaque and it just does the right thing.   Since you often find yourself doing a series of not-quite trivial things with date/time values, this is a great tool.

    I peeked at the source code once.   Wow.   “Glad somebody wrote that (and wrote it so well) ... glad it wasn’t me.”

Re^2: Comparing dates in Perl
by DaveMonk (Acolyte) on Apr 08, 2012 at 20:07 UTC
    Hey thanks man. Appreciate it.