Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Get consistent response from to_char 'D' using different NLS's

PericlesJul 26 2022

Hello
I'm using to_char(date,'D') in a package procedure to get the day of the week of a given date. If something happens on weekend (to_char(date,'D') is 1 or 7 ) the procedure should do A else B.
I'm facing some issues because the procedure will be called from an APEX 22.1 session affected by user's NLS. If the user's NLS is EN-US to_char('23-JUL-2022','D') returns 7, but if the user NLS is SP-AR then the same function returns 6, affecting the result of the procedure
I've found that DBMS_SESSION.SET_NLS can be used, but I'm quite worried about what would be the impact of that change for the end user.
Wonder if there is another way to find out if a date is Saturday or Sunday no mater NLS format.
Appreciate your comments.

This post has been answered by Frank Kulash on Jul 26 2022
Jump to Answer

Comments

Frank Kulash

Hi, Pericles
If dt is a DATE, then

 dt- TRUNC (dt, IW') >= 5

will be true if (and only if) dt is a Saturday or Sunday, regardless or any NLS settings.

Frank Kulash
Answer

You could also tell TO_CHAR explicitly to use a particular language, like this:

TO_CHAR (dt, 'Dy', 'NLS_DATE_LANGUAGE=ENGLISH') IN ('Sat', 'Sun')

regardless of what the system or session NLS settings are. However, you can't tell TO_CHAR to use a particular NLS_TERRITORY, which is what governs the 'D' format.

Marked as Answer by Pericles · Jul 26 2022
Pericles

Thank you so much Frank.
Appreciate your comment.

1 - 3

Post Details

Added on Jul 26 2022
3 comments
109 views