7-6. Adding Hours, Minutes, Seconds, or Days to a Given Date


One of your applications requires that you have the ability to add any number of days, hours, minutes, or seconds to a given date and time to produce a new date and time.


Create functions that add each of these time values to TIMESTAMP dataypes that are passed as an argument. Each of these functions will return the given time plus the amount of time that is passed in as argument. The following three functions will provide the ability to add hours, minutes, seconds, or days to a given time. Each of these functions returns the calculated date and time using the TIMESTAMP datatype.

CREATE OR REPLACE FUNCTION calc_hours(time_to_change IN TIMESTAMP,                      timeval ...

Get Oracle and PL/SQL Recipes: A Problem-Solution Approach now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.