Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

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

by poolpi (Hermit)
on Jan 30, 2009 at 13:22 UTC ( [id://740162]=note: print w/replies, xml ) Need Help??


in reply to How do i compare dates with format dd.mm.yy

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: note [id://740162]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (3)
As of 2024-03-29 02:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found