When in PHP application I specify
ALTER SESSION SET NLS_DATE_FORMAT = 'YYYY-MM-DD HH24:MI:SS';
ALTER SESSION SET NLS_DATE_LANGUAGE = 'RUSSIAN';
the output data format is as expected 2020-01-31 21:21:47 But when I add
ALTER SESSION SET NLS_TERRITORY = 'CIS';
NLS_DATE_FORMAT doesn't take effect, NLS_TERRITORY overrides it. 31.01.20
The
nls_date_format(amongst other settings) is derived from thenls_territory. So when you set the territory, the database also sets the date format to the default for this area:So you need to set the date format after the territory:
Or - better still - use an explicit format mask in your conversions: