Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: Compare two dates

by soonix (Canon)
on Jul 22, 2019 at 21:40 UTC ( [id://11103172]=note: print w/replies, xml ) Need Help??


in reply to Re: Compare two dates
in thread Compare two dates

This
The semantics are compatible with Perl's sort() function; it returns -1 if $dt1 < $dt2, 0 if $dt1 == $dt2, 1 if $dt1 > $dt2.
is not compatible with your code
say DateTime->compare( $d1, $d2 ) ? $d1->ymd .' is greater than ' . $d2->ymd : $d2->ymd .' is greater or equal to ' . $d1->ymd;
Better would be e.g.
say $d1->ymd . ' is ' . ('earlier than', 'equal to', 'later than')[Dat +eTime->compare( $d1, $d2 ) + 1] . ' ' . $d2->ymd;

Log In?
Username:
Password:

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

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

    No recent polls found