I'm trying to create a function that returns the day of the week for a specified date, and I tried the one that's on the bottom, but unsuccessful.
SELECT DAYOFWEEK(‘2015-07-04’);
I'm trying to create a function that returns the day of the week for a specified date, and I tried the one that's on the bottom, but unsuccessful.
SELECT DAYOFWEEK(‘2015-07-04’);
Use TO_CHAR for that.
select
to_char(date'2015-07-04', 'Day'),
to_char(date'2015-07-04', 'Day', 'NLS_DATE_LANGUAGE=american'),
to_char(date'2015-07-04', 'Day', 'NLS_DATE_LANGUAGE=german'),
to_char(date'2015-07-04', 'DY'),
to_char(date'2015-07-04', 'D') -- result depends on NLS_TERRITORY which you cannot specify here unfortunately
from dual;
The string delimiter in SQL is ', but I guess that was just a copy & paste error? A date literal in Oracle starts with DATE. To select a single value in Oracle, select from DUAL. You can optionally specify a language when you want to see weekday names. As to the day number, this depends on a session setting, unfortunately, with 1 being either Sunday or Monday.
Try: select to_char(to_date('2015-07-04','yyyy-dd-mm'), 'DAY') I think it should work.
Referred from: How to get the week day name from a date?