AppLib ADD HOURS

From LucidDB Wiki
Jump to: navigation, search

Contents

Syntax

APPLIB.ADD_HOURS ( timestamp_expression, num_of_hours )

Purpose

Adds a number of hours to a timestamp. A negative number will result in a subtraction of hours.

Input

  • timestamp_expression [TIMESTAMP]: original timestamp before the addition of hours
  • num_of_hours [INTEGER]: the number of hours to add; will subtract hours if negative number is supplied

Output

  • [TIMESTAMP] - returns a timestamp with the added number of days, returns null on null input

Example

VALUES( APPLIB.ADD_HOURS(TIMESTAMP'2010-12-30 1:59:04', 60),
    APPLIB.ADD_HOURS(TIMESTAMP'2006-10-4 11:15:00', -9) )

RETURNS:

APPLIB.ADD_HOURS(TIMESTAMP'2010-12-30 1:59:04', 60) APPLIB.ADD_HOURS(TIMESTAMP'2006-10-4 11:15:00', -9)
2011-01-01 13:59:04.0 2006-10-04 02:15:00.0

Source Code

create or replace function applib.add_hours(ts timestamp, n int)
returns timestamp
specific add_hours_timestamp
deterministic
contains sql
return (
  ts + cast(cast(n as bigint)*60*60*1000 as interval day(10) to hour));
Personal tools
Product Documentation