LucidDbAppLib ADD DAYS
From Eigenpedia
Contents |
Syntax
APPLIB.ADD_DAYS ( [ date_expression | timestamp_expression ], num_of_days )
Purpose
Adds a number of days to a date or timestamp. A negative number will result in a subtraction of days.
Input
- date_expression [DATE]: original date before the addition of days
- timestamp_expression [TIMESTAMP]: original timestamp before the addition of days
- num_of_days [INTEGER]: the number of days to add, will subtract days if negative number is supplied
Output
- [DATE/TIMESTAMP] - returns a new date or timestamp with the added number of days. The return datatype is the same datatype as what was passed in as input. Returns null on null input
Example
VALUES( APPLIB.ADD_DAYS(DATE'2006-10-4', 3),
APPLIB.ADD_DAYS(TIMESTAMP'2006-10-4 11:15:00', 3),
APPLIB.ADD_DAYS(DATE'2010-3-2', -10) )
RETURNS:
| APPLIB.ADD_DAYS(DATE'2006-10-4', 3) | APPLIB.ADD_DAYS(TIMESTAMP'2006-10-4 11:15:00', 3) | APPLIB.ADD_DAYS(DATE'2010-3-2', -10) |
|---|---|---|
| 2006-10-07 | 2006-10-07 11:15:00.0 | 2010-02-20 |
Source Code
create or replace function applib.add_days(d date, n int) returns date specific add_days_date deterministic contains sql return ( d + cast(cast(n as bigint)*24*60*60*1000 as interval day(10)) ); create or replace function applib.add_days(ts timestamp, n int) returns timestamp specific add_days_timestamp deterministic contains sql return ( ts + cast(cast(n as bigint)*24*60*60*1000 as interval day(10)) );
Return to LucidDbAppLib page

