Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Comparing dates in Perl

by ikegami (Patriarch)
on Apr 04, 2012 at 19:50 UTC ( [id://963520]=note: print w/replies, xml ) Need Help??


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 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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://963520]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-19 23:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found