in reply to Re: Compare two dates
in thread Compare two dates
Perl also ships with the module Time::Piece which overloads numeric comparison operators. Therefore you could handle a broader variety of date formats, and also achieve basic date validation using the strptime method it provides
I just wanted to second this, and the use of modules in general. Of course, everyone in this thread who pointed out that YYYY-MM-DD works with string comparisons (iff the format is exactly the same for both strings, and this is validated beforehand) is correct, and for simply determining lt/eq/gt, it'll work fine. But in my experience, one date/time task is usually followed closely by another. Next thing you know, your requirements will change, and someone will ask you to check if a date is within a certain number of days of another date. And then you'll need a module anyway.
One advantage that DateTime has over Time::Piece is that it handles time zones, which may become important if you need to handle times as well - as long as it's just dates, Time::Piece should be just fine.
|
|---|