Oracle datediff evaluate the date, Week, and month Functions
Oracledatediff date week month create or replace function datediff (type in varchar2, startTime in varchar2, endTime in varchar2, v in varchar2) return number as v_result number; SQL _1 varchar2 (200 ); begin dbms_output.put_line ('1'); if (type = 'day') then SQL _1: = 'select' | v | '(TO_NUMBER (to_date (''' | startTime | ''', ''yyyy-MM-DD '') -to_date (''' | endTime | ''', ''yyyy-MM-DD '') from dual'; dbms_output.put_line ('1 '); elsif (type = 'month') then SQL _1: = 'select' | v | '(months_between (to_date (''' | startTime | ''', ''yyyy-MM-DD '')-to_date (''' | endTime | ''', ''yyyy-MM-DD'') from dual '; dbms_output.put_line ('1'); elsif (type = 'Week ') then dbms_output.put_line ('1'); SQL _1: = 'select' | v | '(TO_NUMBER (to_date (''' | startTime | ''', ''yyyy-MM-DD '') -to_date (''' | endTime | ''', ''yyyy-MM-DD '')/7) from dual'; end if; dbms_output.put_line (SQL _1 ); execute immediate SQL _1 into v_result; return (v_result); end; -- first EXECUTE the above function, so that you can write this function in Oracle. You can use this method: select datediff ('Week ', '2014-09-01', '2014-08-01 ', 'round') from dual; -- Description 'Week' indicates week, 'month' indicates month, 'day' indicates the day-two dates are passed in the middle-the fourth parameter: round the week or month with 'row', round up with 'ceil 'and round down with 'floor'