Number of days in a year [message #21525] |
Fri, 09 August 2002 08:38  |
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   |
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   |
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 :)
|
|
|
|