This page last modified: Jun 30 2004
I've include a little working Perl code snippet. Dates are an interesting problem, especially if the dates are read or entered by humans. SQL timestamps have to be munged in order to be reformatted for humans. Sadly, there is a difference between SQL's ISO standard and the output of the Linux date ISO standard, so dates often have to be munged to get them back into SQL. SQL has some date functions, but they are incomplete. The Linux date command will do just about anything, and is fairly easy to use and well documented with man date. So, it is simplest to use date to parse and reformat dates. The date command will read any common standard, and reformat to any other common standard. Given that flexibility, it is easier to just put unix time stamps into the db as integers. Unix time stamps are also easy to test older/newer. Oh, and date will do a --date="1 month ago" which correctly crosses year/month/leap year boundaries. The one glaring thing date doesn't easily do is read a unix timestamp, so I use Perl's localtime() for that, and just reformat the answer with date. date can be slow, however, not so slow that you can tell when doing a few dates to/from a user interface.