Skip to main content

date.format

Description

Formats a date/time value using a simple token-based pattern. Supports common date/time tokens and optional timezone offset adjustment.

Syntax

flex.date.format(datetime, pattern, timezone)

Parameters

ParameterTypeRequiredDescription
datetimeDate/number/stringYesThe date/time value to format
patternstringNoFormat pattern using tokens (default: 'YYYY-MM-DDTHH:mm:ss[Z]')
timezonestringNoTimezone offset like "+02:00" or "-05:00"

Supported Pattern Tokens

TokenDescriptionExample
YYYY4-digit year2024
MM2-digit month (01-12)03
DD2-digit day (01-31)15
HH2-digit hour (00-23)14
mm2-digit minute (00-59)30
ss2-digit second (00-59)45
SSS3-digit milliseconds123
[Z]Literal 'Z' characterZ

Returns

Type: string

A formatted date/time string according to the pattern. Returns null if the input date is invalid.

Examples

Example 1: Basic Date Formatting

WITH datetime('2024-03-15T14:30:00Z') AS dt
RETURN flex.date.format(dt, 'YYYY-MM-DD') AS date

Output:

date
----------
2024-03-15

Example 2: Full DateTime with Time

WITH datetime('2024-03-15T14:30:45Z') AS dt
RETURN flex.date.format(dt, 'YYYY-MM-DD HH:mm:ss') AS formatted

Output:

formatted
-------------------
2024-03-15 14:30:45

Example 3: Custom Format with Timezone

WITH datetime('2024-03-15T14:30:00Z') AS dt
RETURN flex.date.format(dt, 'DD/MM/YYYY HH:mm', '+02:00') AS localTime

Output:

localTime
-----------------
15/03/2024 16:30

(Adjusted for +02:00 timezone)

Example 4: Formatting Node Timestamps

MATCH (e:Event)
RETURN e.name, flex.date.format(e.timestamp, 'YYYY-MM-DD') AS eventDate
ORDER BY e.timestamp DESC

Notes

  • Returns null for invalid date inputs
  • Default pattern is ISO8601-like: 'YYYY-MM-DDTHH:mm:ss[Z]'
  • Timezone parameter adjusts the displayed time for the given offset
  • All calculations are UTC-based internally
  • Milliseconds are optional in the pattern

See Also