apoc.date.add

Details

Syntax

apoc.date.add(time, unit, addValue, addUnit)

Description

Adds a unit of specified time to the given timestamp.

Arguments

Name

Type

Description

time

INTEGER

The timestamp to add time to.

unit

STRING

The unit the given timestamp is in.

addValue

INTEGER

The amount of time to add to the given timestamp.

addUnit

STRING

The unit the added value is in.

Returns

INTEGER

Usage Examples

The unit and addUnit parameters support the following values:

  • ms, milli, millis, milliseconds

  • s, second, seconds

  • m, minute, minutes

  • h, hour, hours

  • d, day, days

The computed value will be in the unit specified by the unit parameter.

The following adds 10,000 milliseconds to the current datetime:

WITH apoc.date.add(datetime().epochMillis, "ms", 10000, "ms") AS output
RETURN outputinMs, datetime({epochMillis: output}) AS datetime;
Results
outputinMs datetime

1604509597386

2020-11-04T17:06:37.386Z

The following adds 1 day to the current datetime:

WITH apoc.date.add(datetime().epochMillis, "ms", 1, "day") AS output
RETURN outputinMs, datetime({epochMillis: output}) AS datetime;
Results
outputinMs datetime

1604596506209

2020-11-05T17:15:06.209Z

The following adds 1 hour to 12 hours:

RETURN apoc.date.add(12, "hour", 1, "hour") AS outputinHours
Results
outputinHours

13

The following adds 1 hour to 34 minutes:

RETURN apoc.date.add(34, "minutes", 1, "hour") AS outputInMinutes;
Results
outputInMinutes

94