4
select TO_CHAR(to_date(sysdate, 'DD-MON-YYYY'), 'DAY') FROM DUAL; 

When I run this query the output was : SUNDAY. But we know today is Tuesday(1-1-2013). And

then changed the query as

select TO_CHAR(to_date('01-JAN-2013', 'DD-MON-YYYY'), 'DAY') FROM DUAL;

answer was :TUESDAY.

then Changed query as

select TO_CHAR(to_date(sysdate+1, 'DD-MON-YYYY'), 'DAY') FROM DUAL;

answer is :MONDAY.

When I using the sysdate why it is show SUNDAY as output?

I am new in oracle db. Please help me.

3
  • SYSDATE is already a date. Why would you think it was necessary to use TO_DATE() on it?
    – APC
    Commented Jan 1, 2013 at 6:06
  • @APC Now I am studying basics of the oracle, and going through this just tried some examples and this query developed myself from some other query. Commented Jan 1, 2013 at 6:31
  • when I using SELECT TO_CHAR(TO_DATE(sysdate, 'DD-MM-RRRR'), 'DAY') from dual; The Ans: TUESDAY Commented Jan 1, 2013 at 6:43

3 Answers 3

6

use this:

 select TO_CHAR(sysdate, 'DAY') FROM DUAL;

you are using this :

 to_date(sysdate, 'DD-MON-YYYY') 

which is giving you date=1/1/0013 which is sunday

2

Please refer the documentation for sysdate here. Sysdate is already a date data type.

Your example query is inappropriate as to_date function takes first parameter as String not date.

Try the simple query below:

     select TO_CHAR(sysdate, 'DAY') FROM DUAL; 

This should return TUESDAY as output.

0
2

To_date is used to convert a strin to date. As sysdate is already a date, one must not add add to_date.

1
  • Strictly speaking, sysdate contains both date AND time components. If you, for example, compare sysdate to a DATE field value of today, = comparison will fail. You will need to_date() to make = match. Commented May 31, 2018 at 12:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.