in reply to Re: Compare two dates
in thread Compare two dates
Yeah, that's correct, but it is slightly more complicated than it needs to be. Using the lt and gt string comparison operators is a bit simpler:
Or:my $d1 = '2019-06-08'; my $d2 = '2019-06-08'; if ($d1 lt $d2) { print "\n$d1 is smaller.\n"; } elsif ($d2 gt $d1) { print "\n$d1 is larger.\n"; } else { print "\nThe dates are equal!\n"; }
my $d1 = '2019-06-08'; my $d2 = '2019-06-08'; print $d1 lt $d2 ? "$d1 smaller" : $d1 gt $d2 ? "$d1 larger" : "Dates are equal";
|
---|
In Section
Seekers of Perl Wisdom