How do I get the current year using SQL on Oracle ?

How do I get the current year using SQL on Oracle ?

Asked on December 26, 2018 in SQL Server.
Add Comment


  • 4 Answer(s)

    Try to use to_char. For example,

    select to_char(sysdate, 'YYYY') from dual;
    

    Here is the code ,

    select trunc(sysdate, 'YEAR') begin_year
         , add_months(trunc(sysdate, 'YEAR'), 12)-1/24/60/60 last_second_year
    from dual;
     
    BEGIN_YEAR LAST_SECOND_YEAR
    ----------- ----------------
    01/01/2009 31/12/2009
    
    Answered on December 26, 2018.
    Add Comment

    Use the code given below,

    SELECT *
      FROM TABLE
    WHERE EXTRACT( YEAR FROM date_field) = EXTRACT(YEAR FROM sysdate)
    
    Answered on December 26, 2018.
    Add Comment

    The extract(datetime) function will give year, month, day, minute, even second. So try to use extract(datetime).

    select extract(year from sysdate) from dual;
    
    Answered on December 26, 2018.
    Add Comment
    BETWEEN 
        TO_DATE('01/01/**currentYear** 00:00:00', 'DD/MM/YYYY HH24:MI:SS')
        AND
        TO_DATE('31/12/**currentYear** 23:59:59', 'DD/MM/YYYY HH24:MI:SS')
    
    Answered on January 13, 2019.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.