Wednesday, February 22, 2017

How to calculate no of days in an 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 <= 20
 12  );

THE_YEAR          DAYS_IN_YEAR
-------------------- ------------
01-JAN-2009 12 00:00           365
01-JAN-2008 12 00:00           366



or

select to_date('01-JAN-'||to_char(to_number(to_char(sysdate,'YYYY'))+1),'DD-MM-YYYY')-trunc(sysdate,'YYYY') cnt
from dual
/


or


select add_months(trunc(sysdate,'YYYY'),12) -trunc(sysdate,'YYYY') cnt from dual




select
   to_char(trunc(input_date, 'YYYY'), 'YYYY')  as "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 <= 20
)
order by "Year" desc
;

Year DAYS_IN_YEAR
---- ------------
2009          365
2008          366

No comments:

Post a Comment

To generate a PDF using JavaScript in Oracle APEX from a collection

  To generate a PDF using JavaScript in Oracle APEX from a collection, you can follow these steps: 1. Create a button or link on your APEX p...