Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Problem passing date to SQL

by runrig (Abbot)
on Aug 18, 2015 at 15:36 UTC ( [id://1139030]=note: print w/replies, xml ) Need Help??


in reply to Problem passing date to SQL

You should either use a TO_DATE() function in your sql, or set the nls date/timestamp format(s), e.g.:
... WHERE date_column = TO_DATE(?, 'YYYY-MM-DD') ... my $date_str = '2015-08-08'; $sth->execute($date_str); # OR my $date_fmt = my $datetime_fmt = my $datetime_tz_fmt = 'YYYY-MM-DD HH +24:MI:SS'; $dbh->do("alter session set nls_date_format=$date_fmt"); $dbh->do("alter session set nls_timestamp_format=$datetime_fmt"); $dbh->do("alter session set nls_timestamp_tz_format=$datetime_tz_fmt") +; ... WHERE date_column = ? ... my $date_str = '2015-08-08'; $sth->execute($date_str);
Update: Oh, and I agree w/below about doing a LIKE against a date (although it CAN work in Oracle, it is incredibly bad practice). It should be, e.g.:
$start_date = '2015-08-01'; $end_date = '2015-09-01'; ... WHERE date_column >= ? and date_column < ? ... $sth->execute($start_date, $end_date);
Update: Fixed date fmt. Twice.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1139030]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-04-25 23:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found