to_date function with sysdate

前端 未结 3 1986
别跟我提以往
别跟我提以往 2020-12-21 03:44
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(

相关标签:
3条回答
  • 2020-12-21 04:21

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

    0 讨论(0)
  • 2020-12-21 04:28

    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

    0 讨论(0)
  • 2020-12-21 04:47

    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 讨论(0)
提交回复
热议问题