O'Reilly logo

Oracle and PL/SQL Recipes: A Problem-Solution Approach by Matt Arena, Josh Juneau

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

Problem

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.

Solution

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required