Thi*_*Not 5

DateTime :: Format :: DBI可以将DateTime对象转换为您正在使用的数据库引擎的相应字符串表示形式.这很好,因为它允许您切换RDBMS而无需重写日期解析代码.

use DateTime;
use DateTime::Format::DBI;
use DateTime::Format::Strptime;
use DBI;

my $dbh = DBI->connect( ... ) or die $DBI::errstr;

my $date = '12/22/13 21:48:06';
my $str_parser = DateTime::Format::Strptime->new(pattern => '%D %T');

# Parse string into a DateTime object
my $dt = $str_parser->parse_datetime($date);

my $db_parser = DateTime::Format::DBI->new($dbh);

$dbh->do("INSERT INTO table VALUES (?)", undef,
         $db_parser->format_datetime($dt));

# For MySQL, inserts 2013-12-22 21:48:06
Run Code Online (Sandbox Code Playgroud)

对于您正在处理的内容而言,这可能过于苛刻,但对于需要同时连接到多种类型数据库的项目而言可能非常方便.目前支持IBM DB2,Microsoft SQL,MySQL,Oracle,PostgreSQL,SQLite和Sybase.