A datetime value function creates a temporal instant or duration value. Refer to Values and Types for date and time string formats.
Creates a value of type DATE (LOCAL DATE).
| Syntax | date([<param>]) | ||
| Arguments | Name | Type | Description |
<param> | STRING, RECORD, or 3 INTs | A date string, a record with year/month/day fields, or three integers (year, month, day) | |
| Return Type | DATE | ||
GQL// returns the current local date, date() is equivalent to CURRENT_DATE RETURN date(), CURRENT_DATE
GQLRETURN date("1993-05-09"), date("1993-5-9"), date("19930509"), date("1993/05/09"), date("1993/5/9"), date({year: 1993, month: 5, day: 9}), date(1993, 5, 9)
Creates a value of type LOCAL TIME. time() is a synonym.
| Syntax | local_time([<param>]) | ||
| Arguments | Name | Type | Description |
<param> | STRING or RECORD | A time string or a record with hour/minute/second fields and optionally millisecond, microsecond, or nanosecond | |
| Return Type | LOCAL TIME | ||
GQL// returns the current local time, local_time() is equivalent to LOCAL_TIME RETURN local_time(), LOCAL_TIME
GQLRETURN local_time("03:02:11.700000000"), local_time("03:02:11"), local_time("03:02"), local_time("030211"), local_time("030211.700000000"), local_time({hour: 3, minute: 2, second: 11}), local_time({hour: 3, minute: 2, second: 11, millisecond: 700}), local_time({hour: 3, minute: 2, second: 11, microsecond: 700}), local_time({hour: 3, minute: 2, second: 11, nanosecond: 700})
Creates a value of type LOCAL DATETIME.
| Syntax | local_datetime([<param>]) | ||
| Arguments | Name | Type | Description |
<param> | STRING or RECORD | A datetime string or a record with year/month/day/hour/minute/second fields and optionally millisecond, microsecond, or nanosecond | |
| Return Type | LOCAL DATETIME | ||
GQL// returns the current local datetime, local_datetime() is equivalent to LOCAL_TIMESTAMP RETURN local_datetime(), LOCAL_TIMESTAMP
GQLRETURN local_datetime("1993-05-09T03:02:11.70"), local_datetime("1993-05-09 03:02:11"), local_datetime("1993/05/09 03:02:11"), local_datetime("1993/5/9 03:02:11"), local_datetime("19930509T030211"), local_datetime("19930509 030211"), local_datetime({year: 1993, month: 5, day: 9, hour: 3, minute: 2, second: 11}), local_datetime({year: 1993, month: 5, day: 9, hour: 3, minute: 2, second: 11, millisecond: 700}), local_datetime({year: 1993, month: 5, day: 9, hour: 3, minute: 2, second: 11, microsecond: 700}), local_datetime({year: 1993, month: 5, day: 9, hour: 3, minute: 2, second: 11, nanosecond: 700})
Creates a value of type ZONED TIME.
| Syntax | zoned_time([<param> [, <timezone>]]) | ||
| Arguments | Name | Type | Description |
[<param>] | STRING, RECORD, or TIME | A time string with timezone, a record with hour/minute/second/timezone fields and optionally millisecond, microsecond, or nanosecond | |
<timezone> | STRING | Target timezone offset (e.g., "+05:30", "Z") used to convert the first argument to a different timezone | |
| Return Type | ZONED TIME | ||
GQL// returns the current local zoned time, zoned_time() is equivalent to CURRENT_TIME RETURN zoned_time(), CURRENT_TIME
GQLRETURN zoned_time("12:20:02+08:00"), zoned_time("12:20:02Z"), zoned_time({hour: 12, minute: 20, second: 2, timezone: "+08:00"}), zoned_time({hour: 12, minute: 20, second: 2, timezone: "+08:00", millisecond: 500}), zoned_time({hour: 12, minute: 20, second: 2, timezone: "-06:00", microsecond: 700}), zoned_time({hour: 12, minute: 20, second: 2, timezone: "Z", nanosecond: 700})
Convert an existing time to a different timezone:
GQLRETURN zoned_time("12:20:02+08:00", "+05:30")
Creates a value of type ZONED DATETIME.
| Syntax | zoned_datetime(<param> [, <timezone>]) | ||
| Arguments | Name | Type | Description |
<param> | STRING, RECORD, TIMESTAMP, or ZONED DATETIME | A datetime string with timezone, a record with year/month/day/hour/minute/second/timezone fields and optionally millisecond, microsecond, or nanosecond | |
<timezone> | STRING | Target timezone offset (e.g., "+05:30", "Z") used to convert the first argument to a different timezone | |
| Return Type | ZONED DATETIME | ||
GQL// returns the current local datetime, zoned_datetime() is equivalent to CURRENT_TIMESTAMP RETURN zoned_datetime(), CURRENT_TIMESTAMP
GQLRETURN zoned_datetime("2025-01-01T12:20:02+08:00"), zoned_datetime("2025-01-01T12:20:02Z"), zoned_datetime({year: 2025, month: 1, day: 1, hour: 12, minute: 20, second: 2, timezone: "+08:00"}), zoned_datetime({year: 2025, month: 1, day: 1, hour: 12, minute: 20, second: 2, timezone: "+08:00", millisecond: 500}), zoned_datetime({year: 2025, month: 1, day: 1, hour: 12, minute: 20, second: 2, timezone: "-06:00", microsecond: 700}), zoned_datetime({year: 2025, month: 1, day: 1, hour: 12, minute: 20, second: 2, timezone: "Z", nanosecond: 700})
Convert an existing datetime to a different timezone:
GQLRETURN zoned_datetime("2025-01-01T12:20:02+08:00", "+05:30")
Returns the current zoned datetime in the server's local timezone. It is equivalent to CURRENT_TIMESTAMP.
| Syntax | now() |
| Return Type | ZONED DATETIME |
GQLRETURN now(), CURRENT_TIMESTAMP
Creates a value of type DURATION.
| Syntax | duration(<durationStr>) | ||
| Arguments | Name | Type | Description |
<durationStr> | STRING | An ISO 8601 duration string (e.g., "P2Y5M", "P3DT4H") | |
| Return Type | DURATION | ||
GQLRETURN duration("P2Y5M"), duration("P3DT4H30M")
Adds a specified time interval to a given date.
| Syntax | date_add(<time>, <interval>, <unit>) | ||
| Arguments | Name | Type | Description |
<time> | Temporal | The initial time | |
<interval> | INT | The number of units to add (positive value to add, negative to subtract) | |
<unit> | STRING | The unit of time to add, which can be year, month, day, hour, minute, or second | |
| Return Type | DATETIME | ||
GQLRETURN date_add("1970-1-1", -1, "hour")
Result:
JSON{ "_type": "localDatetime", "year": 1969, "month": 12, "day": 31, "hour": 23, "minute": 0, "second": 0, "nanosecond": 0 }
GQLRETURN date_add("1970-1-1", 10, "year")
Result:
JSON{ "_type": "localDatetime", "year": 1980, "month": 1, "day": 1, "hour": 0, "minute": 0, "second": 0, "nanosecond": 0 }
Computes the difference between two dates (time1 - time2) and returns the result as a specified unit of time.
| Syntax | date_diff(<time1>, <time2>, <unit>) | ||
| Arguments | Name | Type | Description |
<endTime> | Temporal | The first time | |
<time2> | Temporal | The second time | |
<unit> | STRING | The unit of difference, which can be day, hour, minute, or second | |
| Return Type | DATETIME | ||
GQLRETURN date_diff("1970-01-01 10:00:00", "1970-01-01 12:00:20", "minute")
Result: -120
Returns a number (from 0 to 6, where 0 = Sunday and 6 = Saturday) representing the day of the week for a given date.
| Syntax | day_of_week(<time>) | ||
| Arguments | Name | Type | Description |
<time> | STRING or Temporal | A date/time string or a temporal value (DATE, LOCAL DATETIME, ZONED DATETIME, LOCAL TIME, TIMESTAMP) | |
| Return Type | INT | ||
GQLRETURN day_of_week("2024-12-5")
Result: 4
Extracts the year from a date or datetime value.
| Syntax | year(<temporal>) | ||
| Arguments | Name | Type | Description |
<temporal> | STRING or Temporal | A date/time string or a temporal value (DATE, LOCAL DATETIME, ZONED DATETIME, LOCAL TIME, TIMESTAMP) | |
| Return Type | INT | ||
GQLRETURN year("2025-03-15"), year(date("2025-03-15"))
Extracts the month from a date or datetime value.
| Syntax | month(<temporal>) | ||
| Arguments | Name | Type | Description |
<temporal> | STRING or Temporal | A date/time string or a temporal value (DATE, LOCAL DATETIME, ZONED DATETIME, LOCAL TIME, TIMESTAMP) | |
| Return Type | INT | ||
GQLRETURN month("2025-03-15"), month(date("2025-03-15"))
Extracts the day from a date or datetime value.
| Syntax | day(<temporal>) | ||
| Arguments | Name | Type | Description |
<temporal> | STRING or Temporal | A date/time string or a temporal value (DATE, LOCAL DATETIME, ZONED DATETIME, LOCAL TIME, TIMESTAMP) | |
| Return Type | INT | ||
GQLRETURN day("2025-03-15"), day(date("2025-03-15"))
Extracts the hour from a time or datetime value.
| Syntax | hour(<temporal>) | ||
| Arguments | Name | Type | Description |
<temporal> | STRING or Temporal | A date/time string or a temporal value (DATE, LOCAL DATETIME, ZONED DATETIME, LOCAL TIME, TIMESTAMP) | |
| Return Type | INT | ||
GQLRETURN hour("2025-03-15 14:30:45"), hour(local_datetime("2025-03-15 14:30:45"))
Extracts the minute from a time or datetime value.
| Syntax | minute(<temporal>) | ||
| Arguments | Name | Type | Description |
<temporal> | STRING or Temporal | A date/time string or a temporal value (DATE, LOCAL DATETIME, ZONED DATETIME, LOCAL TIME, TIMESTAMP) | |
| Return Type | INT | ||
GQLRETURN minute("2025-03-15 14:30:45"), minute(local_datetime("2025-03-15 14:30:45"))
Extracts the second from a time or datetime value.
| Syntax | second(<temporal>) | ||
| Arguments | Name | Type | Description |
<temporal> | STRING or Temporal | A date/time string or a temporal value (DATE, LOCAL DATETIME, ZONED DATETIME, LOCAL TIME, TIMESTAMP) | |
| Return Type | INT | ||
GQLRETURN second("2025-03-15 14:30:45"), second(local_datetime("2025-03-15 14:30:45"))
Computes the duration between two temporal values.
| Syntax | duration_between(<temporal1>, <temporal2>) | ||
| Arguments | Name | Type | Description |
<temporal1> | DATE, DATETIME, TIMESTAMP | Start temporal value | |
<temporal2> | DATE, DATETIME, TIMESTAMP | End temporal value | |
| Return Type | DURATION | ||
GQLRETURN duration_between(date("2025-01-01"), date("2025-03-15"))
Result:
JSON{ "seconds": 6307200, "nanoseconds": 0 }
Formats a temporal value as a string using a Java SimpleDateFormat-style pattern.
| Syntax | dateformat(<temporal>, <format>) | ||
| Arguments | Name | Type | Description |
<temporal> | Temporal | A datetime value or a parsable string | |
<format> | STRING | A Java SimpleDateFormat-style pattern (e.g., "yyyy-MM-dd", "yyyy-MM-dd HH:mm:ss") | |
| Return Type | STRING | ||
Supported pattern tokens (case-sensitive; the longest match wins):
| Token | Meaning | Example |
|---|---|---|
yyyy / yy | 4- or 2-digit year | 2024 / 24 |
MMMMM / MMMM / MMM / MM / M | Month: one-letter abbreviation / full name / short name / 2-digit / 1-digit | J / January / Jan / 01 / 1 |
dd / d | Day of month: padded / unpadded | 02 / 2 |
EEEE / EEE / EE / E | Day name: full / 3-letter abbreviation | Monday / Mon |
HH / H | Hour 0-23, always 2-digit padded | 15 |
hh / h | Hour 1-12: padded / unpadded | 03 / 3 |
mm / m | Minute: padded / unpadded | 04 / 4 |
ss / s | Second: padded / unpadded | 05 / 5 |
SSSSSSSSS / SSSSSS / SSS / SS / S | Fractional second: 9 / 6 / 3 / 2 / 1 digits (use after . or ,) | 123456789 / 123456 / 123 / 12 / 1 |
a | AM/PM marker | PM |
XXX / XX / X | ISO 8601 zone offset | -07:00 / -0700 / -07 |
Z | RFC 822 zone offset | -0700 |
z | Time zone abbreviation | MST |
GQLRETURN dateformat(date("2025-03-15"), "yyyy-M-d") AS value1, dateformat(local_datetime("2025-03-15T14:30:45"), "yyyy-MM-dd HH:mm:ss") AS value2 dateformat(CURRENT_DATE, "'today is' yyyy-MM-dd") AS value3 // single-quote escape
Result:
| value1 | value2 | value3 |
|---|---|---|
| "2025-3-15" | "2025-03-15 14:30:45" | "today is 2026-05-18" |