views:

68

answers:

2

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 ('SAT', 'SUN');
+3  A: 

As of Oracle 11g, yes. The only viable region agnostic alternative that I've seen is as follows:

SELECT *
FROM mytable
WHERE MOD(TO_CHAR(my_date, 'J'), 7) + 1 IN (6, 7);
ninesided
A: 

Not an answer to the question. But some more information. There are many more SQL tricks with date.

to_char(sysdate, 'd') --- day of a week, 1,2,3 .. to 7
to_char(sysdate, 'dd') --- day of a month, 1,2,3 .. to 30 or 31
to_char(sysdate, 'ddd') --- day of a year, 1,2,3 .. to 365 or 366
to_char(sysdate, 'w') --- week of a month, 1,2,3,4 or 5
to_char(sysdate, 'ww') --- week of a year, 1,2,3 .. to 52

More here: to_char function.

Guru
none of these solve the problem, the first is dangerous as "day of week" is region dependent, for example: 1 = Sunday in the US, Monday in the UK.
ninesided
True and accepted. And I dint claim to answer the question, just added more information. Your answer did solve the problem.
Guru