in reply to Comparing and increamenting dates in Perl

Corion has listed the "usual suspects". Basically if you want to do date math efficiently with dates that are within the past ~century, this requires a trip to "epoch" time. Unix has a time for this and Macintosh O/S has another time. What this amounts to is generating an integer number of seconds that is plus/minus from the epoch date/time. You convert date/time strings into this integer value and then add/subtract a number of seconds from this "epoch based" value and then convert that integer back to a string.

If you just want to compare or sort date/times without going through this conversion hassle, I would advise using a format like: 2010-05-12 (YYYY-MM-DD). Leading zero'es are important! A string sort of dates like that will yield the correct order. So that is how to do compares and sorts of dates. For calculations using dates, see above.

  • Comment on Re: Comparing and increamenting dates in Perl