I've got a couple of suggestions for you:

  1. localtime? - Perhaps you might be interested in something you have a little more direct control over - Date::Format maybe?
  2. prepare? How about do - When you expect to get rows out of your SQL statement one option is to prepare a Statement Handle Object first. Since you're doing an UPDATE, you really shouldn't be getting any rows back. Try
    my $cur_time = time2str("%c", time) ; $dbh->do("UPDATE Schedules SET Date = ? WHERE ID = ?", undef, $cur_time, $id) ;
    Errors may be caught in $dbh->errstr
  3. Placeholders - In the 2nd item I use question marks as placeholders. The format for do is $dbh->do($statement, \%attr, @bind_values);. You'll probably not need attrs, so undef should suffice. Placeholders are great because they make it easy to read the SQL and DBI will do the escaping of the values for you.
  4. Using prepare - If you still would like to use prepare I'd recommended using placeholders:
    my $sth = $dbh->prepare("UPDATE Schedules SET Date = ? WHERE ID = ?"); my $cur_time = time2str("%c", time) ; $sth->execute($cur_time, $id) ;
    This may be prefered if you're going to be executing that $sth in a few places. Once $sth is prepared, it may be executed with different values multiple times.

Hope that helps =)

Update: BTW, I don't know what $id looks like, but if it's non-numeric, that's probably what UPDATE is barfing on: Needs escaping... but placeholders take care of that stuff =)

-Ducky


In reply to Re: Dates and SQL by ducky
in thread Dates and SQL by JungleBoy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.