简体   繁体   English

带时间戳的获取和插入日期

[英]Fetching and inserting date with time stamp

I am writing a perl script which copies data from a table in one db to the same table in other DB. 我正在编写一个perl脚本,该脚本将数据从一个数据库中的一个表复制到另一个数据库中的同一表。 I am using DBI to obtain connection to DBS. 我正在使用DBI获得与DBS的连接。 I noticed that when I am copying data,it's not copied properly. 我发现复制数据时,复制不正确。
In source table if date is like this-'04/22/1996 13:51:15 PM' 在源表中,如果日期是这样的-'04 / 22/1996 13:51:15 PM'
In destination table it's appearing like this-'22 APR 1996'. 在目标表中,它看起来像是“ 1996年4月22日”。 Can anyone help me in copying exact date? 有人可以帮我复制确切的日期吗?

Thanks in advance 提前致谢

#!/usr/bin/env perl
use DateTime::Format::Strptime;
my $datetimestr = '04/22/1996 13:51:15 PM';
# 1) parse datetime
my $parser = DateTime::Format::Strptime->new(
    pattern=>'%m/%d/%Y %H:%M:%S %p', 
    on_error  => 'croak',
);
my $dt = $parser->parse_datetime($datetimestr,);
# 2) format datetime for your database format
warn $dt->strftime('%Y-%m-%d %H:%M:%S');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM