Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

How do i compare dates with format dd.mm.yy

by cab (Beadle)
on Jan 18, 2002 at 13:11 UTC ( [id://139774]=perlquestion: print w/replies, xml ) Need Help??

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

  • Comment on How do i compare dates with format dd.mm.yy

Replies are listed 'Best First'.
Re: How do i compare dates with format dd.mm.yy
by metadoktor (Hermit) on Jan 18, 2002 at 14:24 UTC
    Use Date::Calc from CPAN. Specifically, you'd want to look at Delta_Days or Delta_YMD; or you could use Mktime to convert both dates to seconds and then compare the seconds.
Re: How do i compare dates with format dd.mm.yy
by fuzzysteve (Beadle) on Jan 18, 2002 at 18:23 UTC
    It depends on how you want to compare them.

    If you just want to check which is later, reverse the order of the parts, i.e. yy.mm.dd. (Make sure you keep all fields fixed width, i.e. zero padded if necessary.)

    Then simply compare them as strings! However, you are likely to run into the "Y2K" problem, since your years are only two digits.

Re: How do i compare dates with format dd.mm.yy
by cab (Beadle) on Jan 18, 2002 at 15:41 UTC
Re: How do i compare dates with format dd.mm.yy
by poolpi (Hermit) on Jan 30, 2009 at 13:22 UTC
    Using DateTime and DateTime::Format::Duration:
    #!/usr/bin/perl use strict; use warnings; use DateTime; use DateTime::Format::Duration; my @dt; for (qw( 30.01.08 05.03.08 )) { local @_ = split /\./; push @dt, DateTime->new( year => $_[2] + 2000, month => $_[1], day => $_[0], time_zone => "Europe/Paris" ); } my $dur = $dt[1]->subtract_datetime( $dt[0] ); $dur->is_negative and warn $dt[1]->dmy . 'is older than ' . $dt[0]->dmy . "\n"; # Choose the pattern to feet your needs my $dtfd = DateTime::Format::Duration->new( pattern => '%V weeks, %e days' ); my $formated_dtd = $dtfd->format_duration($dur); print <<QUOTE; Difference in weeks and days, between @{[$dt[1]->dmy]} and @{[$dt[0]->dmy]}: $formated_dtd. QUOTE
    Date::Simple parses date strings and creates numerically comparable objects...
    # Difference in days between two dates: $diff = date('2001-08-27') - date('1977-10-05');

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-04-16 17:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found