Determine if Oracle date is on a weekend?

前端 未结 5 945
南笙
南笙 2020-12-03 01:50

Is this the best way to determine if an Oracle date is on a weekend?

select * from mytable
where 
TO_CHAR (my_date, \'DY\', \'NLS_DATE_LANGUAGE=ENGLISH\') IN         


        
5条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-03 02:01

    MOD(TO_CHAR(my_date, 'J'), 7) + 1 IN (6, 7)
    

    is NOT correct! The day number of weekend days may be 6 & 7, or 7 and 1, depending on the NLS-settings.

    So the PROPER test (irrespective of NLS-settings) is this one mentioned before:

    TO_CHAR (my_date, 'DY', 'NLS_DATE_LANGUAGE=ENGLISH') IN ('SAT', 'SUN')
    

提交回复
热议问题