Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
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;