How to get cx_Oracle.Date() formatted according NLS_LANG ?
- What versions are you using?
platform.platform: Windows-10-10.0.18362-SP0 sys.maxsize > 2**32: True platform.python_version: 3.8.6 cx_Oracle.version: 8.0.1 cx_Oracle.clientversion: (19, 8, 0, 0, 0)
- Describe the problem
Expect to format cx_Oracle.Date() display with NLS_LANG
- Include a runnable Python script that shows the problem.
export NLS_LANG=German_Germany.utf8
var = cx_Oracle.Date(2020, 1, 12) print(var)
the output is: 2020-01-12
expect output: 12.01.2020
Python dates are not going to pay attention to Oracle environment variables! If you want a Python date to output in that format you need to do this instead:
var.strftime("%d.%m.%Y")
NLS_LANG is only going to affect dates converted to strings in the database. So this will also do what you intend:
cursor.execute("select to_char(sysdate) from dual")
Hope that explains things!
thanks anthony-tuininga -Gary