如何使用perl脚本将日期时间格式传递给sql server?

时间:2013-06-04 17:06:15

标签: sql-server perl

#!/usr/bin/perl

      use DBI;
      use Data::Dumper;
      use strict;


       my $DSN = q/dbi:ODBC:SQLSERVER/;
       my $uid = q/username/;
       my $pwd = q/password/;

       my $first_param=723454;
       my $current_date="2012-10-25 00:30:21";
       my $after_2min="2012-10-25 05:47:41";


       my $dbh = DBI->connect($DSN,$uid,$pwd) or die "Coudn't Connect SQL"; 

       my $sql2 = "insert reverise_call_main_menu call_number,call_originate_time,call_inbetween_time,call_after_2min_time) values(?,?,?,?)";
       my $sth2 = $dbh->prepare($sql2);
       $sth2->execute($first_param,$current_date,'null',$after_2min);

       $sth2->finish;
       $dbh->disconnect;

每当我执行程序时,我都会遇到以下错误:

输出: -

DBD :: ODBC :: st执行失败:[unixODBC] [FreeTDS] [SQL Server]从字符串转换datetime时转换失败。 (SQL-22007)

1 个答案:

答案 0 :(得分:0)

错误消息表明SQL Server不喜欢datetime字符串的格式。您可能希望使用DateTime::Format::DBI来帮助您格式化。