Here you go

Thursday, February 13, 2014

Oracle SQL to calculate Number of Days in a Year


Query Returns Number of Days in Year:


select
   trunc(input_date, 'YYYY')  as the_year,
   add_months(trunc(input_date, 'YYYY'), 12)
   -
   trunc(input_date, 'YYYY')  as days_in_year
from
(
  select
      add_months(sysdate, -12* level) as input_date
   from dual
   connect by level <= 2012
   );

Query/SQL Returns Days on Row / Generate a range of dates using SQL in Oracle

The simple and direct answer to this Question is:

select trunc(sysdate, 'YYYY') + (level-1) as the_day
from dual
connect by level <= to_number(to_char(last_day(add_months(trunc(sysdate, 'YYYY'),11)), 'DDD'))