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

前端 未结 6 2295
清酒与你
清酒与你 2020-12-04 14:21

I need to add the current year as a variable in an SQL statement, how can I retrieve the current year using SQL?

i.e.

  BETWEEN 
    TO_DATE(\'01/01/**         


        
6条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-04 14:37

    Since we are doing this one to death - you don't have to specify a year:

    select * from demo
    where  somedate between to_date('01/01 00:00:00', 'DD/MM HH24:MI:SS')
                    and     to_date('31/12 23:59:59', 'DD/MM HH24:MI:SS');
    

    However the accepted answer by FerranB makes more sense if you want to specify all date values that fall within the current year.

提交回复
热议问题