Skip to content
Advertisement

Binding dates to SQL in Python for cx_Oracle

I am using the following query to select logs fro a logs table.

SELECT * FROM LOGS  WHERE LOG_DATE BETWEEN TO_TIMESTAMP(:date_start, 'MM-DD-YYYY') AND TO_TIMESTAMP(:date_end, 'MM-DD-YYYY')

I have the following dictionary of parameters:

{'date_start': '02-24-20', 'date_end': '02-24-20'}

and executing the query as follows :

cursor.execute(query, params)

Now the problem is I am not getting any values for this date range. But if I execute the query in Oracle, by specifying the dates, it is working. What is wrong here ?

Advertisement

Answer

If you specified format mask as 'MM-DD-YYYY', why do you then provide only two digits for year ('02-24-20')? Provide 4 digits.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement