Jump to content

how to retrive day from data


vegad

Recommended Posts

i have try this and i got the period of 2004 and 2005 . at that time an operation was carried out ..in this data i put some date from calander and some of them are sunday and saturday.......but i dont know how to retrive a day like i want sunday......my real qus is that.....For the period of 2004-2005 find out the number of operation carried out on a saturday and sunday....i m using sql*plus...SQL> edWrote file afiedt.buf 1 select op_Date 2 from operation 3* where op_date between '1-jan-2004' and '31-dec-2005'SQL> /Hit <RETURN> to continue ...OP_DATE---------11-JAN-04 02-JUN-0414-AUG-0426-NOV-0419-MAR-0527-APR-0531-JUL-057 rows selected.SQL> this are the operation carried out in year 2004 2005 but i want how many operation carried out on sundya and saturday.....i want day insted of date....which i found by my querry...thaks.....plz reply me as soon as possible...thanks again for the ans of my first qus but i m sorry i not setisfied with that.....i m sorry........ :):):):blink:

Link to comment
Share on other sites

If you are using SQL*Plus, then you must be using an Oracle database.Here is a reference of Oracle date functions:http://www.psoug.org/reference/date_func.htmlThis is an example they give to get dates that are not on the weekend:

	CurDate := CurDate+1;	DayNum := TO_CHAR(CurDate, 'D');	IF DayNum BETWEEN 2 AND 6 THEN	  Counter := Counter + 1;

So, using the TO_CHAR function with a date, and "D" to get the day of the week, you can find out what day it is. Since 2-6 are weekdays, Saturday and Sunday will either be 0 and 1 or 1 and 7. I would give specific examples, but I don't have Oracle. I found that page through Google, so you can probably do some search for Oracle date examples to find what you need.

Link to comment
Share on other sites

I HAVE TRY THIS CODE AFTER U GIVE ME SUGESTION....select OP_DATE,to_char(Op_date, 'DAY')OPER_ONfrom operationwhere op_date between '1-jan-2004' and '31-dec-2005'/ AND I GOT THIS TYPE OF RESULT......SHOWN BELOWSQL> EDWrote file afiedt.buf 1 select OP_DATE,to_char(Op_date, 'DAY')OPER_ON 2 from operation 3* where op_date between '1-jan-2004' and '31-dec-2005'SQL> /Hit <RETURN> to continue ...OP_DATE OPER_ON--------- ---------11-JAN-04 SUNDAY02-JUN-04 WEDNESDAY14-AUG-04 SATURDAY26-NOV-04 FRIDAY19-MAR-05 SATURDAY27-APR-05 WEDNESDAY31-JUL-05 SUNDAY7 rows selected.SQL> BUT I ONLY WANT SATURDAY AND SUBDAY FROM DATA,...CAN U GIVE ME ANY SUGESTION.....I WANT ONLY 4 ROWS....WITH SATURDAY AND SUNDAY.......I M WAITING FOR U RREPLY..THNKS FOR GIVE ME ANS..OF MY QUS.....WAITHING 4 UR REPLY...... :):):blink::)

Link to comment
Share on other sites

I understand what you want, and I understand you're waiting for a reply.You only changed the select clause, you need to change the where clause to filter the results.where op_date between '1-jan-2004' and '31-dec-2005' and (OPER_ON='SATURDAY' or OPER_ON='SUNDAY')

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...