This topic describes how to use the date function TIMESTAMPADD in Realtime Compute.

Syntax

TIMESTAMP TIMESTAMPADD(interval,INT int_expr,TIMESTAMP datetime_expr)
DATE TIMESTAMPADD(interval,INT int_expr,DATE datetime_expr)       

Input parameters

Parameter Data type
interval VARCHAR
int_expr INT
datetime_expr TIMESTAMP or DATE
The following table lists the valid interval values.
Valid interval value Description
FRAC_SECOND An interval in milliseconds.
SECOND An interval in seconds.
MINUTE An interval in minutes.
HOUR An interval in hours.
DAY An interval in days.
WEEK An interval in weeks.
MONTH An interval in months.
QUARTER An interval in quarters.
YEAR An interval in years.

Description

Adds the integer expression int_expr to the date or datetime expression datetime_expr and returns the current time of the TIME type in the session time zone.

The data type of the returned result of the TIMESTAMPADD function is the same as that of the datetime_expr parameter.

Example

  • Test data
    a (TIMESTAMP) b (DATE)
    2018-07-09 10:23:56 1990-02-20
  • Test statements
    SELECT 
    TIMESTAMPADD(HOUR,3,a) AS `result1`
    TIMESTAMPADD(DAY,3,b) AS `result2`
    FROM T1;
  • Test results
    result1 (TIMESTAMP) result2 (DATE)
    2018-07-09 13:23:56.0 1990-02-23