Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pl sql how to get the day of the week for oracle db date

Tags:

sql

oracle

I have oracle date , I want to translate it to my date , for instance 24.7.2011 is sunday so i want a function to return 1 , for 25.7.2011 I want it to return 2 and so on...

I have been searching the wwb for examples but with no successes please help me.

like image 432
yoav.str Avatar asked Jul 26 '11 11:07

yoav.str


People also ask

How do I get the current day in PL SQL?

The PLSQL SYSDATE function will returns current system date and time on your database. There is no any parameter or argument for the SYSDATE function. The SYSDATE function returns a date value. Note that the SYSDATE function return date and time as “YYYY-MM-DD HH:MM:SS” (string) or as YYYYMMDDHHMMSS (numeric).

What is the first day of the week in Oracle?

In Oracle, you use the NLS_TERRITORY parameter to set which day the week should start on. You can change it just for your session, e.g.: ALTER SESSION SET NLS_TERRITORY=German; Then Monday becomes the first day of the week.


2 Answers

The Oracle function for this is TO_DATE with the 'D' format model:

SQL> select to_char (date '2011-07-24', 'D') d from dual;

D
-
7

As you can see, this returns 7 for Sunday, not 1, when I run it. The value returned varies according to your NLS settings. If necessary you could do this to get what you want:

SQL> select to_char (date '2011-07-24'+1, 'D') d from dual;

D
-
1

More details about Oracle's date format models can be found here

like image 123
Tony Andrews Avatar answered Sep 28 '22 04:09

Tony Andrews


just you have to write to_char(your_date_column_name,'D') it will give the same answer what you have asked

just click here for more details

like image 27
pratik garg Avatar answered Sep 28 '22 05:09

pratik garg