SubtractDays

The SubtractDays function subtracts n number of days from the first input parameter.

Syntax

SubtractDays(<instant|date_time|date|offset_date_time|zoned_date_time>, <long>)

Return Type

Determined by the data type of the first input parameter value. Valid input parameter types are: instant, date_time, date, offset_date_time, zoned_date_time.

Details

The SubtractDays function allows both positive and negative long values in the second input parameter. Positive values cause the date value to decrease, while negative values “add” days from the given input “date” parameter.

Examples

/* Add 1, 30, and 365 days to incentive_date */

select incentive_date,
SubtractDays(incentive_date,1) example_1_day,
SubtractDays(incentive_date, 30) example_30_days,
SubtractDays(incentive_date,365) example_365_days
from xactly.xc_order_stage limit 1;

screen-shot-2016-10-17-at-2-47-41-pm

 

/* Example using instant data type */

select Now() as now_instant,
SubtractDays(Now(),4) as instant_example_add_4
from Empty();

screen-shot-2016-10-17-at-2-47-46-pm

 

/* Example using negative value to add days */

eval SubtractDays(ToDate('2014-04-01'),-10);

screen-shot-2016-10-17-at-2-49-27-pm

Related Functions

AddDays

DiffDays