apoc.date.add

Function APOC Core

apoc.date.add(12345, 'ms', -365, 'd') given a timestamp in one time unit, adds a value of the specified time unit

Signature

apoc.date.add(time :: INTEGER?, unit :: STRING?, addValue :: INTEGER?, addUnit :: STRING?) :: (INTEGER?)

Input parameters

Name Type Default

time

INTEGER?

null

unit

STRING?

null

addValue

INTEGER?

null

addUnit

STRING?

null

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;
Table 1. 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;
Table 2. 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
Table 3. Results
outputinHours

13

The following adds 1 hour to 34 minutes:

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

94