Date and time functions

EQL provides functions for working with time, dateTime, and duration data types.

EQL supports normal arithmetic operations between these data types.

All aggregation functions can be applied on these types except for SUM, which cannot be applied to time or dateTime types.

Note:

In all cases, the internal representation of dates and times is on an abstract time line with no time zone. On this time line, all days are assumed to have exactly 86400 seconds. The system does not track, nor can it accommodate, leap seconds. This is equivalent to the SQL date, time, and timestamp data types that specify WITHOUT TIMEZONE. ISO 8601 ("Data elements and interchange formats - Information interchange - Representation of dates and times") recommends that, when communicating dates and times without a time zone to other systems, they be represented using Zulu time, which is a synonym for GMT. The Dgraph conforms to this recommendation.
The following table summarizes the supported date and time functions:
Function Return Data Type Purpose
CURRENT_TIMESTAMP

SYSTIMESTAMP

dateTime

dateTime

Constants representing the current date and time (at an arbitrary point during query evaluation) in GMT and server time zone, respectively.
CURRENT_DATE

SYSDATE

dateTime

dateTime

Constants representing current date (at an arbitrary point during query evaluation) in GMT and server time zone, respectively.
TO_TIME

TO_DATETIME

TO_DURATION

time

dateTime

duration

Constructs a timestamp representing time, date, or duration, using an expression.
EXTRACT integer Extracts a portion of a dateTime value, such as the day of the week or month of the year.
TRUNC dateTime Rounds a dateTime value down to a coarser granularity.
TO_TZ

FROM_TZ

dateTime

dateTime

Returns the given timestamp in a different time zone.

Note that using CURRENT_DATE, CURRENT_TIMESTAMP, SYSDATE, or SYSTIMESTAMP affects performance because those functions are not cached. The other functions in the table are cached.

The following table summarizes supported operations:
Operation Return Data Type
time (+|-) duration time
dateTime (+|-) duration dateTime
time - time duration
dateTime - dateTime duration
duration (+|-) duration duration
duration (*|/) double duration
duration /duration double