views:

249

answers:

2

I have data stored in a mySQL table under the column type "timestamp" that I would like to output as an RFC-822 compliant date, for inclusion in a valid RSS feed.

I know how I could simply output the current time as an RFC-822 object using perl, but I haven't figured out how to convert an existing string. The string is formatted like this: YYYY-MM-DD HH:MM:SS

A: 

Does CPAN help here I wonder? How about DateTime::Format::DateParse?

Maxwell Troy Milton King
I tried to figure out that -- and a few other modules on CPAN -- but they seemed far too convoluted, and required using multiple modules (one to convert my timestamp to a "time from epoch" and another to convert that to the correct output).I'm sure there's a more elegant solution than the one I ended up using, but I couldn't find it.
WinnPh
A: 

Here's what ended up working for me:

use POSIX qw( strftime );
...
$timestamp =~ /^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2})$/;
$rssTS = strftime('%a, %d %b %Y %T %Z', $6, $5, $4, $3, $2 - 1, $1 - 1900, -1, -1, -1);
WinnPh