0

I am trying to do this

startdate = "20160123"
enddate = "20160204"
cmd = "select identification_number from bug where submitted_date >= TO_DATE(:1,'dd-MON-yy') and submitted_date <= TO_DATE(:2,'dd-MON-yy')"
cursor.execute(cmd,(startdate,enddate))

I get an error

cursor.execute(cmd,(sdate,edate))
cx_Oracle.DatabaseError: ORA-01861: literal does not match format string

I saw previous threads regarding this error but nothing solved my problem

user2471313
  • 63
  • 1
  • 3
  • 10

1 Answers1

2

I am not sure how startdate and enddate is translated to :1 and :2 but if it does, then the issue with date format. You are passing YYYYMMDD and you casting it as DD-MON-YYYY . Try to change it. Also you are missing from clause.

And I'd used between clause instead.

select identification_number 
from <your_table>
where 
submitted_date between 
TO_DATE(:1,'YYYYMMDD') and TO_DATE(:2,'YYYYMMDD')

If this works, then use same date format in your code

startdate = "20160123"
enddate = "20160204"
cmd = "select identification_number from <your_table> where submitted_date between TO_DATE(:1,'YYYYMMDD') and TO_DATE(:2,'YYYYMMDD')"
Utsav
  • 7,914
  • 2
  • 17
  • 38