in reply to DBI SQL Query Question

I can't spot any syntax errors - what is the error message?

A piece of advice though, don't use backticks to call the date command - for one, it's not portable, and two, it's not as efficient as calling localtime (and use strict!):

my $month = (localtime)[4] + 1; my $day = (localtime)[3];

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
F--F--F--F--F--F--F--F--
(the triplet paradiddle)

Replies are listed 'Best First'.
Re: (jeffa) Re: DBI SQL Query Question
by count0 (Friar) on Jan 11, 2002 at 23:02 UTC

    Additionally, to get the zero-padding functionality of date(1)'s %m and %d, use sprintf().
    my $month = sprintf ("%02d", (localtime)[4]+1); my $day = sprintf ("%02d", (localtime)[3]);

    Two other options for formatting your date/time are: POSIX's strftime, and Date::Format.
Re(2): (jeffa) DBI SQL Query Question
by dmmiller2k (Chaplain) on Jan 12, 2002 at 00:18 UTC

    Or even more similar to using date:

    use POSIX qw( strftime ); # ... my $month = strftime('%m'); # same as `date '+%m'` my $day = strftime('%d'); # same as `date '+%d'`

    Any date/time formatting you could get with date is possible with <CDOE>strftime()</CODE> (since under the hood, date calls it too!).

    Perhaps this particular use is best accomplished with localtime, but it could be helpful to know about the concordance between date and <CDOE>POSIX::strftime()</CODE>.

    dmm

    If you GIVE a man a fish you feed him for a day
    But,
    TEACH him to fish and you feed him for a lifetime
Re: (jeffa) Re: DBI SQL Query Question
by liquidc00l (Novice) on Jan 12, 2002 at 00:03 UTC
    Ha, I guess an error message would help, but I don't have one, if I run the SQL command by hand it returns the results I expected, but as soon as I put it in the .pl script...no luck! TA

      What data types are your Month and Day columns? Presumably int from your example, but you never know...

      Problems with prepared statements are notoriously difficult to simulate at the prompt, since command-line SQL utilities (isql, sqlplus, et al) don't support the concept.

        You assume right, the table is very simple and those two fields are both int.