in reply to Converting localtime to SQL format

If you want to put the current time / date in a MySQL database, why don't you create a table with a fieldtype date/time and insert your query using now()?
eg:
# Datefield is of type: datetime my $sth = $dbh->prepare('insert into tableName (DateField, OtherField) + values (now(),?)');


"We all agree on the necessity of compromise. We just can't agree on when it's necessary to compromise." - Larry Wall.

Replies are listed 'Best First'.
Re^2: Converting localtime to SQL format
by Deib (Sexton) on Mar 30, 2005 at 07:40 UTC
    That was simple :S
    Here I was reading hundreds of tutorials x_X
    Thanks a lot jbrugger :)
Re^2: Converting localtime to SQL format
by jhourcle (Prior) on Mar 30, 2005 at 13:01 UTC

    For the perpetually lazy, most databases have some way of defining default values. (although, with dynamic values such as this, you might have to use a trigger).

    In mysql, you can just use the column type TIMESTAMP.

    It's been a while since I've played with oracle, but if setting the column 'DEFAULT SYSDATE' doesn't work. (It might've been 'DEFAULT SYSDATE()'), you can always use an insert trigger.