Date & Math Functions
date.add()
Add time to a timestamp.
Syntax: date.add(timestamp, value, unit)
Parameters:
| Parameter | Type | Description |
|---|---|---|
timestamp |
Long |
The timestamp (in milliseconds) |
value |
Long |
Amount to add (can be negative) |
unit |
String |
Unit of the value (ms, s, m, h, d) |
Returns: Long - New timestamp
APOC Compatible: apoc.date.add
RETURN date.add(date.currentTimestamp(), 1, "d") AS tomorrow
// Returns: timestamp for tomorrow
RETURN date.add(date.currentTimestamp(), -1, "h") AS oneHourAgo
// Returns: timestamp for 1 hour ago
date.convert()
Convert a timestamp between units.
Syntax: date.convert(timestamp, fromUnit, toUnit)
Returns: Long - Converted timestamp
APOC Compatible: apoc.date.convert
date.currentTimestamp()
Get the current timestamp in milliseconds.
Syntax: date.currentTimestamp()
Returns: Long - Current timestamp in milliseconds since epoch
APOC Compatible: apoc.date.currentTimestamp
RETURN date.currentTimestamp() AS now
// Returns: 1705314600000 (example)
date.field()
Extract a specific field from a timestamp.
Syntax: date.field(timestamp, field)
Returns: Long - Field value
APOC Compatible: apoc.date.field
date.fields()
Extract all fields from a timestamp as a map.
Syntax: date.fields(timestamp)
Returns: Map - Map of date fields
APOC Compatible: apoc.date.fields
date.format()
Format a timestamp to a date string.
Syntax: date.format(timestamp, unit, format)
Parameters:
| Parameter | Type | Description |
|---|---|---|
timestamp |
Long |
The timestamp value |
unit |
String |
Unit of the timestamp (ms, s, m, h, d) |
format |
String |
Date format pattern (Java SimpleDateFormat) |
Returns: String - Formatted date string
APOC Compatible: apoc.date.format
RETURN date.format(1705314600000, "ms", "yyyy-MM-dd HH:mm:ss") AS result
// Returns: "2024-01-15 10:30:00"
date.fromISO8601()
Parse an ISO 8601 string to timestamp.
Syntax: date.fromISO8601(dateString)
Returns: Long - Timestamp in milliseconds
APOC Compatible: apoc.date.fromISO8601
RETURN date.fromISO8601("2024-01-15T10:30:00Z") AS result
// Returns: 1705314600000
date.parse()
Parse a date string to timestamp.
Syntax: date.parse(dateString, format)
Returns: Long - Timestamp in milliseconds
APOC Compatible: apoc.date.parse
date.systemTimezone()
Get the system’s default timezone.
Syntax: date.systemTimezone()
Returns: String - Timezone ID (e.g., "America/New_York")
APOC Compatible: apoc.date.systemTimezone
date.toISO8601()
Convert a timestamp to ISO 8601 format.
Syntax: date.toISO8601(timestamp)
Returns: String - ISO 8601 formatted string
APOC Compatible: apoc.date.toISO8601
RETURN date.toISO8601(1705314600000) AS result
// Returns: "2024-01-15T10:30:00+00:00"
math.cosh()
Calculate the hyperbolic cosine.
Syntax: math.cosh(x)
Returns: Double - Hyperbolic cosine value
APOC Compatible: apoc.math.cosh
math.maxDouble()
Get the maximum double value.
Syntax: math.maxDouble()
Returns: Double - Maximum double value
APOC Compatible: apoc.math.maxDouble
math.maxLong()
Get the maximum long value.
Syntax: math.maxLong()
Returns: Long - Maximum long value (9223372036854775807)
APOC Compatible: apoc.math.maxLong
math.minLong()
Get the minimum long value.
Syntax: math.minLong()
Returns: Long - Minimum long value
APOC Compatible: apoc.math.minLong
math.round()
Round a number to the nearest integer, or to a given number of decimal places using a chosen rounding mode. This is the namespaced entry point for the built-in round() function and has identical semantics.
Syntax: math.round(value [, precision [, mode]])
Parameters:
| Parameter | Type | Description |
|---|---|---|
value |
Number |
The number to round |
precision |
Integer |
(Optional) Number of decimal places to keep |
mode |
String |
(Optional) Rounding mode: |
Returns: Double - The rounded value, or null if any argument is null
An unknown rounding mode raises an error rather than falling back to the default. NaN and infinity are returned unchanged.
APOC Compatible: apoc.math.round
RETURN math.round(2.5) AS result
// Returns: 3.0
RETURN math.round(3.456, 1) AS result
// Returns: 3.5
RETURN math.round(3.456, 2, 'FLOOR') AS result
// Returns: 3.45
math.sigmoid()
Calculate the sigmoid function.
Syntax: math.sigmoid(x)
Returns: Double - Sigmoid value (0-1)
APOC Compatible: apoc.math.sigmoid
RETURN math.sigmoid(0) AS result
// Returns: 0.5
RETURN math.sigmoid(10) AS result
// Returns: ~0.9999
math.sigmoidPrime()
Calculate the derivative of the sigmoid function.
Syntax: math.sigmoidPrime(x)
Returns: Double - Sigmoid derivative
APOC Compatible: apoc.math.sigmoidPrime
math.sinh()
Calculate the hyperbolic sine.
Syntax: math.sinh(x)
Returns: Double - Hyperbolic sine value
APOC Compatible: apoc.math.sinh
math.tanh()
Calculate the hyperbolic tangent.
Syntax: math.tanh(x)
Returns: Double - Hyperbolic tangent value
APOC Compatible: apoc.math.tanh
number.format()
Format a number as a string using a DecimalFormat pattern.
Syntax: number.format(number [, pattern])
Parameters:
| Parameter | Type | Description |
|---|---|---|
number |
Number |
The number to format |
pattern |
String |
(Optional) A |
Returns: String - The formatted number, or null if the number or an explicitly passed pattern is null
Formatting always uses the root locale, so the grouping and decimal separators do not depend on the server’s locale.
APOC Compatible: apoc.number.format
RETURN number.format(1234567.891) AS result
// Returns: "1,234,567.891"
RETURN number.format(1000000, '#,###') AS result
// Returns: "1,000,000"
RETURN number.format(0.4567, '#.##%') AS result
// Returns: "45.67%"