[ale] PERL + SQL Dates

michael d. ivey ivey at gweezlebur.com
Tue Apr 27 09:33:08 EDT 2004


On Tue, Apr 27, 2004 at 08:50:11AM -0400, Chris Fowler wrote:
> I'm storing my dates in MySQL as "YYYY-MM-DD HH:MM:SS"  I need to be
> able in perl to convert that time to epoch and also convert an epoch
> into that format.  Anyone have any secrets for me?

# http://search.cpan.org/~msergeant/Time-Piece-1.08/Piece.pm
use Time::Piece;

$date_string = some_sql_retriever_method();

$date_object = Time::Piece->strptime($date_string,
    "%Y-%m-%d %H:%M:%S");

$epoch = $date_object->epoch;

$new_epoch = $epoch + 1000;

$new_date_object = Time::Piece->new($new_epoch);

$new_date_string = $new_date_object->date . " " . $new_date_object->time;

__END__

See also the note about ISO 8601 date/time strings being
"YYYY-MM-DDThh:mm:ss" where T is a literal T.

Ping me for more info if you need it.

-- 
michael d. ivey        [McQ] : "Wonder, rather than doubt, is the
   <ivey at gweezlebur.com>     : root of knowledge."
http://gweezlebur.com/~ivey/ :                       -- Abraham Heschel
 encrypted email preferred   :



More information about the Ale mailing list