in reply to Dates and SQL

use Date::Format;Its perldoc is concise and tells all. Or, if the column is a timestamp field, just write NULL to it

Update: Re: OP reply; Check your database server or DBI driver docs to see what format SQL wants to see. "%c" gives ctime format, which the server may not use. Also, your driver may want $dbi->quote() applied to the data. Placeholder syntax would let you skip quoting and gain efficiency if you do several updates in a run.

After Compline,
Zaxo

Replies are listed 'Best First'.
Re: Re: Dates and SQL
by JungleBoy (Scribe) on Sep 27, 2001 at 06:17 UTC
    I've tried this, unfortunately I get a "Syntax error in UPDATE statement."
    Any other ideas?
    This is what it looks like now:
    my $cur_time = time2str("%c", time()); $sth = $dbh->prepare("UPDATE Schedules SET Date = '$cur_time' WHERE ID + = $id") or die "Couldn't prepare statement: $DBI::errstr; stopped";
      I looks like that your Database doesn't recognise the string as a date. Check what it does accept and format your date accordingly. If you don't have any documentation select back a date and look at how it is formatted. It will most probably accept that as an input
      For easy date formatting I often use the POSIX module's strftime routine to format the date. e.g.
      use POSIX qw(strftime); my $cur_time = strftime "%m %d %Y", localtime;