Links
Comment on page

DATE_ADD

Adds an interval of a specified unit to a given timestamp. Subtraction can be performed by using a negative interval value.

Syntax

DATE_ADD(UNIT, VALUE, TIMESTAMP)

Arguments

UNIT

Type: string
The unit of time to add.
It can be one of the following:
  • year
  • quarter
  • month
  • week
  • day
  • hour
  • minute
  • second
  • millisecond

VALUE

Type: bigint
The integer value of the UNIT to add to TIMESTAMP.
Can be positive (for times in the future) or negative (for times in the past).

TIMESTAMP

Type: timestamp
The timestamp to be modified.

Returns

Type: timestamp
The TIMESTAMP with an INTERVAL of the given NUMBER added to it.

Examples

UNIT
VALUE
TIMESTAMP
Output
day
1
2001-08-22 03:04:05.321
2001-08-23 03:04:05.321
year
5
2001-08-22 03:04:05.321
2006-08-22 03:04:05.321
second
30
2001-08-22 03:04:05.321
2001-08-22 03:04:35.321
quarter
1
2001-08-22 03:04:05.321
2001-11-22 03:04:05.321
quarter
-1
2001-08-22 03:04:05.321
2001-05-22 03:04:05.321
quarter
0
2001-08-22 03:04:05.321
2001-08-22 03:04:05.321
year
1
null
null

Transformation job example

SQL

CREATE JOB function_operator_example
ADD_MISSING_COLUMNS = true
AS INSERT INTO default_glue_catalog.upsolver_samples.orders_transformed_data MAP_COLUMNS_BY_NAME
SELECT
"$event_timestamp",
DATE_ADD('day', 1, "$event_timestamp") AS day_after,
DATE_ADD('day', -1, "$event_timestamp") AS day_before
FROM default_glue_catalog.upsolver_samples.orders_raw_data
WHERE time_filter()
LIMIT 1;

Query result

$event_timestamp
day_after
day_before
2022-08-19 20:11:00.000
2022-08-20 20:11:00.000
2022-08-18 20:11:00.000