I think the problem here is a type problem.  The to_char is returning a
char type and the column is a date type.  To_char returns a character
string and that's failing on the insert due to the table requiring a
date type.  Without knowing exactly what database you are using I can't
give you much help making it work.  In Oracle it would be something
like:

to_date(to_char(SYSDATE, 'Dy-DD-Mon-YYYY HH24:MI'), 'Dy-DD-Mon-YYYY
HH24:MI')

Gordon



-----Original Message-----
From: Kipp, James [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, June 25, 2002 11:41 AM
To: DBI-Users
Subject: Inserting formatted Date


This works fine:
my $sth = $dbh->prepare( "INSERT INTO stats VALUES (SYSDATE,?,?,?,?)" )
        or die "Cannot prepare SQL statements from $DBI::errstr\n";

however if i try to format it like:
my $sth = $dbh->prepare( "INSERT INTO stats VALUES (to_char(SYSDATE, 'Dy
DD-Mon-YYYY HH24:MI'),?,?,?,?)" )
        or die "Cannot prepare SQL statements from $DBI::errstr\n";
--
it fails, it tried quoting it with:
$qstr = q!to_char(sysdate, 'Dy DD-Mon-YYYY HH24:MI')!;
and plugging that in:
$dbh->prepare( "INSERT INTO stats VALUES ($qstr,?,?,?,?)" 
--
failed !

even tried quote():
$qstr = "to_char(sysdate, 'Dy DD-Mon-YYYY HH24:MI')";
$q = $dbh->quote($q);
$dbh->prepare( "INSERT INTO stats VALUES ($q,?,?,?,?)" 
--
still fails

any ideas?

Thanks
Jim

Reply via email to