python-cx_Oracle icon indicating copy to clipboard operation
python-cx_Oracle copied to clipboard

How to get cx_Oracle.Date() formatted according NLS_LANG ?

Open zhua03 opened this issue 5 years ago • 3 comments

  1. 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)

  1. Describe the problem

Expect to format cx_Oracle.Date() display with NLS_LANG

  1. Include a runnable Python script that shows the problem.

export NLS_LANG=German_Germany.utf8

var = cx_Oracle.Date(2020, 1, 12) print(var)

zhua03 avatar Jan 22 '21 04:01 zhua03

the output is: 2020-01-12

expect output: 12.01.2020

zhua03 avatar Jan 22 '21 08:01 zhua03

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!

anthony-tuininga avatar Feb 03 '21 17:02 anthony-tuininga

thanks anthony-tuininga -Gary

zhua03 avatar Feb 05 '21 10:02 zhua03