Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Insert Time Into Datetime Field (perl)

DZone's Guide to

Insert Time Into Datetime Field (perl)

·
Free Resource
insert the current time into a
datetime field in a table while using perl DBI/DBD::mysql
from http://osdir.com/ml/db.mysql.perl/2006-09/msg00001.html

#!/usr/bin/perl -w

use strict;
use DBI;

my $dbh = DBI->connect( "DBI:mysql:test", "root", "");
my $sth = $dbh->prepare( "INSERT INTO a VALUES ( NOW() )" );
$sth->execute();
$sth->finish();

$sth = $dbh->prepare( "SELECT a FROM a" );
$sth->execute();
my ( $time ) = $sth->fetchrow_array();
$sth->finish();

print "The time was [$time]\n";

$dbh->disconnect();

__END__

CREATE TABLE a (
 a datetime NOT NULL default '0000-00-00 00:00:00'
) TYPE=MyISAM;
Topics:

Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

SEE AN EXAMPLE
Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.
Subscribe

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}