Hi,
i've created this function which takes a TIMESTAMP as a parameter and returns a truncated TIMESTAMP (truncated on 30 minutes).
I receive an error ORA-01843 Not a valid date. I haven't got a clue what's going wrong?
create or replace function trunc30 (p_timestamp timestamp) return timestamp
as
p_result timestamp;
begin
SELECT
CASE WHEN (to_number(to_char(p_timestamp,'MI')) < 15 OR to_number(to_char(p_timestamp,'MI')) >= 45) THEN
to_char(trunc(p_timestamp,'HH'),'HH24:MI')
ELSE
to_char(trunc(p_timestamp,'HH') + 30/(60*24),'HH24:MI')
END
into p_result from dual;
return p_result;
end;
I use this code to test the function:
DECLARE
P_TIMESTAMP TIMESTAMP;
v_Return TIMESTAMP;
BEGIN
P_TIMESTAMP := TO_DATE('10/15/2008 15:44','MM/dd/yyyy HH24:MI');
v_Return := TRUNC30(
P_TIMESTAMP => P_TIMESTAMP
);
DBMS_OUTPUT.PUT_LINE('v_Return = ' || v_Return);
END;