Home » SQL & PL/SQL » SQL & PL/SQL » Number of days in a year
Number of days in a year [message #21525] Fri, 09 August 2002 08:38 Go to next message
Alex Mazur
Messages: 17
Registered: March 2002
Junior Member
Hi, Guys!

Does Oracle have built-in function that
returns actual number of days in a year
based on date passed as a parameter ?

Thanks.
Re: Number of days in a year [message #21526 is a reply to message #21525] Fri, 09 August 2002 09:02 Go to previous messageGo to next message
Keith
Messages: 88
Registered: March 2000
Member
There's no in-built function that I know of, but you could write your own, adapting the following:

CREATE OR REPLACE FUNCTION get_days_in_year (p_yr_date IN DATE) RETURN NUMBER IS
p_num_days NUMBER;

BEGIN


SELECT TO_DATE('31-DEC-'||TO_CHAR(p_yr_date, 'yyyy'), 'dd-mon-yyyy') - TO_DATE('01-JAN-'||TO_CHAR(p_yr_date, 'yyyy'), 'dd-mon-yyyy')
INTO p_num_days
FROM DUAL;

RETURN p_num_days;

END;
/

Keith
Re: Number of days in a year [message #21528 is a reply to message #21525] Fri, 09 August 2002 11:00 Go to previous messageGo to next message
Alex Mazur
Messages: 17
Registered: March 2002
Junior Member
Well,

I think, that one is better, or at least faster:
create or replace
FUNCTION get_days_in_year (p_yr_date IN DATE)
RETURN NUMBER
IS
begin

return to_char(to_date('1231'||to_char(p_yr_date,'YYYY'),'MMDDYYYY'),'DDD');

END;

But i'm talking about BUILT-IN ORACLE FUNCTION!!
Thanks anyway :)
Re: Number of days in a year [message #21532 is a reply to message #21528] Fri, 09 August 2002 14:30 Go to previous message
TomazZ
Messages: 7
Registered: August 2002
Junior Member
What about built-in oracle functionS:

select to_number(to_char(add_months(trunc(sysdate,'yyyy'),12)-1,'ddd')) from dual
Previous Topic: ORA-01008: not all variables bound
Next Topic: varchar2(6) vs. varchar(12)
Goto Forum:
  


Current Time: Mon Jul 07 05:14:49 CDT 2025