Find Number of Days in a Year

Your rating: None Average: 3.4 (5 votes)

Number of days in a year can be calculated by finding the 1st day of the next year and subtract that from the 1st day of the current year.

Find first day of next year

 SELECT add_months(TRUNC(sysdate,'y'),12)
  FROM dual;

ADD_MONTHS(TRUNC(SYSDATE,'Y'),12)
-------------------------
01-JAN-09                

1 rows selected

Find first day of current year

SELECT TRUNC(sysdate,'y')
 FROM dual;

TRUNC(SYSDATE,'Y')        
-------------------------
01-JAN-08                

1 rows selected

Finding days for the current year is an easy task now, just subtract the two dates and your done.

 SELECT add_months(TRUNC(sysdate,'y'),12) - TRUNC(sysdate,'y')
  FROM dual;

ADD_MONTHS(TRUNC(SYSDATE,'Y'),12)-TRUNC(SYSDATE,'Y')
----------------------------------------------------
366                                                  

1 rows selected

Please try to help out with unanswered topics on the forum. Chances are you have had the same issue/question some time in your IT career!

Comments

Have a question? Please ask it on the forum instead.

Post new comment

The content of this field is kept private and will not be shown publicly.
CAPTCHA
The question below is to prevent automated spam submissions.
1 + 8 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.