Re: Q: Any add/subtract hours from Date Function Written.

From: Guerry Semones <guerry_at_iluvatar.tip.duke.edu> <guerry_at_iluvatar>
Date: Thu, 5 Jan 1995 13:31:38 -0500 (EST)
Message-ID: <Pine.NXT.3.90.950105125708.8602A-100000_at_iluvatar>


On 5 Jan 1995, Eric Mortensen wrote:

> Has anyone had the need to write a PL/SQL function to add or subtract
> hours from an Oracle Date field. Oracle only supplies a function to
> add or subtract a month from a date field (add_month). This function
> should be able to handle adding or subtracting more then a years worth of
> hours (i.e. can cross more then 1 year boundry). If so, can you please
> E-mail me a copy of your function.

We can add days to a date field. For example:

  • this adds seven days to date

   update appointments set when = when + 7

Oracle takes care of crossing the 1 year boundary:

  • If "when" is: 28-dec-94,07:00:00 am, and you add six days:

   update appt set when=when+6

  • The result is 03-jan-95,07:00:00 am.

Therefore, what you need to do to add hours is very straight forward:

  • this also takes into account partial days and will maintain proper
  • hourly increments, etc.

   update appointments

      set when = when + (number_of_hours / 24)

Good luck!

 Guerry A. Semones

  • My opinions are my own, regardless of who my employer is.
Received on Thu Jan 05 1995 - 19:31:38 CET

Original text of this message