ibtissem ibtissem - 7 months ago 31
Python Question

Not a valid month error

i have a problem with python developpement.
I try to insert records to my database table , but i have this error when i trying to insert using cx_Oracle for python : not a valid month.
And when i try to run this same query in sqldeveloper ,there is no problem
this my code :


cursor.execute("insert into mytable(tableid,tablename,timecreate)values('45125','test',to_timestamp(to_char(sysdate,'dd/mm/yy')))")


I don't know what is the difference?
Have you any idea?

Answer

Assuming you want just the mm/dd/yy (remove hours,mins,sec) from a sysdate and convert to a timestamp, try this instead of your to_timestamp call:

CAST (trunc(SYSDATE) AS TIMESTAMP)

No need to convert to char and back.

Comments