Details for using the datetime()
function.
datetime()
returns the current DateTime value.
If no time zone parameter is specified, the default time zone will be used.
Syntax: datetime([ {timezone} ])
Returns:
A DateTime. |
Arguments:
Name | Description |
---|---|
|
|
|
A string expression that represents the time zone |
Considerations:
If no parameters are provided, |
Query.
RETURN datetime() AS currentDateTime
The current date and time using the local time zone is returned.
currentDateTime |
---|
1 row |
|
Try this query live. none RETURN datetime() AS currentDateTime
Query.
RETURN datetime({ timezone: 'America/Los Angeles' }) AS currentDateTimeInLA
The current date and time of day in California is returned.
currentDateTimeInLA |
---|
1 row |
|
Try this query live. none RETURN datetime( {timezone: 'America/Los Angeles'} ) AS currentDateTimeInLA
datetime.transaction()
returns the current DateTime value using the transaction
clock.
This value will be the same for each invocation within the same transaction.
However, a different value may be produced for different transactions.
Syntax: datetime.transaction([ {timezone} ])
Returns:
A DateTime. |
Arguments:
Name | Description |
---|---|
|
A string expression that represents the time zone |
Query.
RETURN datetime.transaction() AS currentDateTime
currentDateTime |
---|
1 row |
|
Try this query live. none RETURN datetime.transaction() AS currentDateTime
Query.
RETURN datetime.transaction('America/Los Angeles') AS currentDateTimeInLA
currentDateTimeInLA |
---|
1 row |
|
Try this query live. none RETURN datetime.transaction('America/Los Angeles') AS currentDateTimeInLA
datetime.statement()
returns the current DateTime value using the statement
clock.
This value will be the same for each invocation within the same statement.
However, a different value may be produced for different statements within the same transaction.
Syntax: datetime.statement([ {timezone} ])
Returns:
A DateTime. |
Arguments:
Name | Description |
---|---|
|
A string expression that represents the time zone |
Query.
RETURN datetime.statement() AS currentDateTime
currentDateTime |
---|
1 row |
|
Try this query live. none RETURN datetime.statement() AS currentDateTime
datetime.realtime()
returns the current DateTime value using the realtime
clock.
This value will be the live clock of the system.
Syntax: datetime.realtime([ {timezone} ])
Returns:
A DateTime. |
Arguments:
Name | Description |
---|---|
|
A string expression that represents the time zone |
Query.
RETURN datetime.realtime() AS currentDateTime
currentDateTime |
---|
1 row |
|
Try this query live. none RETURN datetime.realtime() AS currentDateTime
datetime()
returns a DateTime value with the specified year, month, day, hour, minute, second, millisecond, microsecond, nanosecond and timezone component values.
Syntax: datetime({year [, month, day, hour, minute, second, millisecond, microsecond, nanosecond, timezone]})
Returns:
A DateTime. |
Arguments:
Name | Description |
---|---|
|
|
|
An expression consisting of at least four digits that specifies the year. |
|
An integer between |
|
An integer between |
|
An integer between |
|
An integer between |
|
An integer between |
|
An integer between |
|
An integer between |
|
An integer between |
|
An expression that specifies the time zone. |
Considerations:
The month component will default to |
The day of the month component will default to |
The hour component will default to |
The minute component will default to |
The second component will default to |
Any missing |
The timezone component will default to the configured default time zone if |
If |
The least significant components in the set |
One or more of |
Query.
UNWIND [
datetime({ year:1984, month:10, day:11, hour:12, minute:31, second:14, millisecond: 123, microsecond: 456, nanosecond: 789 }),
datetime({ year:1984, month:10, day:11, hour:12, minute:31, second:14, millisecond: 645, timezone: '+01:00' }),
datetime({ year:1984, month:10, day:11, hour:12, minute:31, second:14, nanosecond: 645876123, timezone: 'Europe/Stockholm' }),
datetime({ year:1984, month:10, day:11, hour:12, minute:31, second:14, timezone: '+01:00' }),
datetime({ year:1984, month:10, day:11, hour:12, minute:31, second:14 }),
datetime({ year:1984, month:10, day:11, hour:12, minute:31, timezone: 'Europe/Stockholm' }),
datetime({ year:1984, month:10, day:11, hour:12, timezone: '+01:00' }),
datetime({ year:1984, month:10, day:11, timezone: 'Europe/Stockholm' })
] AS theDate
RETURN theDate
theDate |
---|
8 rows |
|
|
|
|
|
|
|
|
Try this query live. none UNWIND [ datetime({year:1984, month:10, day:11, hour:12, minute:31, second:14, millisecond: 123, microsecond: 456, nanosecond: 789}), datetime({year:1984, month:10, day:11, hour:12, minute:31, second:14, millisecond: 645, timezone: '+01:00'}), datetime({year:1984, month:10, day:11, hour:12, minute:31, second:14, nanosecond: 645876123, timezone: 'Europe/Stockholm'}), datetime({year:1984, month:10, day:11, hour:12, minute:31, second:14, timezone: '+01:00'}), datetime({year:1984, month:10, day:11, hour:12, minute:31, second:14}), datetime({year:1984, month:10, day:11, hour:12, minute:31, timezone: 'Europe/Stockholm'}), datetime({year:1984, month:10, day:11, hour:12, timezone: '+01:00'}), datetime({year:1984, month:10, day:11, timezone: 'Europe/Stockholm'}) ] as theDate RETURN theDate
datetime()
returns a DateTime value with the specified year, week, dayOfWeek, hour, minute, second, millisecond, microsecond, nanosecond and timezone component values.
Syntax: datetime({year [, week, dayOfWeek, hour, minute, second, millisecond, microsecond, nanosecond, timezone]})
Returns:
A DateTime. |
Arguments:
Name | Description |
---|---|
|
|
|
An expression consisting of at least four digits that specifies the year. |
|
An integer between |
|
An integer between |
|
An integer between |
|
An integer between |
|
An integer between |
|
An integer between |
|
An integer between |
|
An integer between |
|
An expression that specifies the time zone. |
Considerations:
The week component will default to |
The day of the week component will default to |
The hour component will default to |
The minute component will default to |
The second component will default to |
Any missing |
The timezone component will default to the configured default time zone if |
If |
The least significant components in the set |
One or more of |
Query.
UNWIND [
datetime({ year:1984, week:10, dayOfWeek:3, hour:12, minute:31, second:14, millisecond: 645 }),
datetime({ year:1984, week:10, dayOfWeek:3, hour:12, minute:31, second:14, microsecond: 645876, timezone: '+01:00' }),
datetime({ year:1984, week:10, dayOfWeek:3, hour:12, minute:31, second:14, nanosecond: 645876123, timezone: 'Europe/Stockholm' }),
datetime({ year:1984, week:10, dayOfWeek:3, hour:12, minute:31, second:14, timezone: 'Europe/Stockholm' }),
datetime({ year:1984, week:10, dayOfWeek:3, hour:12, minute:31, second:14 }),
datetime({ year:1984, week:10, dayOfWeek:3, hour:12, timezone: '+01:00' }),
datetime({ year:1984, week:10, dayOfWeek:3, timezone: 'Europe/Stockholm' })
] AS theDate
RETURN theDate
theDate |
---|
7 rows |
|
|
|
|
|
|
|
Try this query live. none UNWIND [ datetime({year:1984, week:10, dayOfWeek:3, hour:12, minute:31, second:14, millisecond: 645}), datetime({year:1984, week:10, dayOfWeek:3, hour:12, minute:31, second:14, microsecond: 645876, timezone: '+01:00'}), datetime({year:1984, week:10, dayOfWeek:3, hour:12, minute:31, second:14, nanosecond: 645876123, timezone: 'Europe/Stockholm'}), datetime({year:1984, week:10, dayOfWeek:3, hour:12, minute:31, second:14, timezone: 'Europe/Stockholm'}), datetime({year:1984, week:10, dayOfWeek:3, hour:12, minute:31, second:14}), datetime({year:1984, week:10, dayOfWeek:3, hour:12, timezone: '+01:00'}), datetime({year:1984, week:10, dayOfWeek:3, timezone: 'Europe/Stockholm'}) ] as theDate RETURN theDate
datetime()
returns a DateTime value with the specified year, quarter, dayOfQuarter, hour, minute, second, millisecond, microsecond, nanosecond and timezone component values.
Syntax: datetime({year [, quarter, dayOfQuarter, hour, minute, second, millisecond, microsecond, nanosecond, timezone]})
Returns:
A DateTime. |
Arguments:
Name | Description |
---|---|
|
|
|
An expression consisting of at least four digits that specifies the year. |
|
An integer between |
|
An integer between |
|
An integer between |
|
An integer between |
|
An integer between |
|
An integer between |
|
An integer between |
|
An integer between |
|
An expression that specifies the time zone. |
Considerations:
The quarter component will default to |
The day of the quarter component will default to |
The hour component will default to |
The minute component will default to |
The second component will default to |
Any missing |
The timezone component will default to the configured default time zone if |
If |
The least significant components in the set |
One or more of |
Query.
UNWIND [
datetime({ year:1984, quarter:3, dayOfQuarter: 45, hour:12, minute:31, second:14, microsecond: 645876 }),
datetime({ year:1984, quarter:3, dayOfQuarter: 45, hour:12, minute:31, second:14, timezone: '+01:00' }),
datetime({ year:1984, quarter:3, dayOfQuarter: 45, hour:12, timezone: 'Europe/Stockholm' }),
datetime({ year:1984, quarter:3, dayOfQuarter: 45 })
] AS theDate
RETURN theDate
theDate |
---|
4 rows |
|
|
|
|
Try this query live. none UNWIND [ datetime({year:1984, quarter:3, dayOfQuarter: 45, hour:12, minute:31, second:14, microsecond: 645876}), datetime({year:1984, quarter:3, dayOfQuarter: 45, hour:12, minute:31, second:14, timezone: '+01:00'}), datetime({year:1984, quarter:3, dayOfQuarter: 45, hour:12, timezone: 'Europe/Stockholm'}), datetime({year:1984, quarter:3, dayOfQuarter: 45}) ] as theDate RETURN theDate
datetime()
returns a DateTime value with the specified year, ordinalDay, hour, minute, second, millisecond, microsecond, nanosecond and timezone component values.
Syntax: datetime({year [, ordinalDay, hour, minute, second, millisecond, microsecond, nanosecond, timezone]})
Returns:
A DateTime. |
Arguments:
Name | Description |
---|---|
|
|
|
An expression consisting of at least four digits that specifies the year. |
|
An integer between |
|
An integer between |
|
An integer between |
|
An integer between |
|
An integer between |
|
An integer between |
|
An integer between |
|
An expression that specifies the time zone. |
Considerations:
The ordinal day of the year component will default to |
The hour component will default to |
The minute component will default to |
The second component will default to |
Any missing |
The timezone component will default to the configured default time zone if |
If |
The least significant components in the set |
One or more of |
Query.
UNWIND [
datetime({ year:1984, ordinalDay:202, hour:12, minute:31, second:14, millisecond: 645 }),
datetime({ year:1984, ordinalDay:202, hour:12, minute:31, second:14, timezone: '+01:00' }),
datetime({ year:1984, ordinalDay:202, timezone: 'Europe/Stockholm' }),
datetime({ year:1984, ordinalDay:202 })
] AS theDate
RETURN theDate
theDate |
---|
4 rows |
|
|
|
|
Try this query live. none UNWIND [ datetime({year:1984, ordinalDay:202, hour:12, minute:31, second:14, millisecond: 645}), datetime({year:1984, ordinalDay:202, hour:12, minute:31, second:14, timezone: '+01:00'}), datetime({year:1984, ordinalDay:202, timezone: 'Europe/Stockholm'}), datetime({year:1984, ordinalDay:202}) ] as theDate RETURN theDate
datetime()
returns the DateTime value obtained by parsing a string representation of a temporal value.
Syntax: datetime(temporalValue)
Returns:
A DateTime. |
Arguments:
Name | Description |
---|---|
|
A string representing a temporal value. |
Considerations:
|
The timezone component will default to the configured default time zone if it is omitted. |
|
|
Query.
UNWIND [
datetime('2015-07-21T21:40:32.142+0100'),
datetime('2015-W30-2T214032.142Z'),
datetime('2015T214032-0100'),
datetime('20150721T21:40-01:30'),
datetime('2015-W30T2140-02'),
datetime('2015202T21+18:00'),
datetime('2015-07-21T21:40:32.142[Europe/London]'),
datetime('2015-07-21T21:40:32.142-04[America/New_York]')
] AS theDate
RETURN theDate
theDate |
---|
8 rows |
|
|
|
|
|
|
|
|
Try this query live. none UNWIND [ datetime('2015-07-21T21:40:32.142+0100'), datetime('2015-W30-2T214032.142Z'), datetime('2015T214032-0100'), datetime('20150721T21:40-01:30'), datetime('2015-W30T2140-02'), datetime('2015202T21+18:00'), datetime('2015-07-21T21:40:32.142[Europe/London]'), datetime('2015-07-21T21:40:32.142-04[America/New_York]') ] AS theDate RETURN theDate
datetime()
returns the DateTime value obtained by selecting and composing components from another temporal value.
In essence, this allows a Date, LocalDateTime, Time or LocalTime value to be converted to a DateTime, and for "missing" components to be provided.
Syntax: datetime({datetime [, year, …, timezone]}) | datetime({date [, year, …, timezone]}) | datetime({time [, year, …, timezone]})
| datetime({date, time [, year, …, timezone]})
Returns:
A DateTime. |
Arguments:
Name | Description |
---|---|
|
|
|
A DateTime value. |
|
A Date value. |
|
A Time value. |
|
An expression consisting of at least four digits that specifies the year. |
|
An integer between |
|
An integer between |
|
An integer between |
|
An integer between |
|
An integer between |
|
An integer between |
|
An integer between |
|
An integer between |
|
An integer between |
|
An integer between |
|
An integer between |
|
An integer between |
|
An integer between |
|
An expression that specifies the time zone. |
Considerations:
If any of the optional parameters are provided, these will override the corresponding components of |
|
Selecting a Time or DateTime value as the |
Selecting a DateTime as the |
Selecting a DateTime or Time as the |
The following query shows the various usages of datetime({date [, year, …, timezone]})
Query.
WITH date({ year:1984, month:10, day:11 }) AS dd
RETURN datetime({ date:dd, hour: 10, minute: 10, second: 10 }) AS dateHHMMSS,
datetime({ date:dd, hour: 10, minute: 10, second: 10, timezone:'+05:00' }) AS dateHHMMSSTimezone,
datetime({ date:dd, day: 28, hour: 10, minute: 10, second: 10 }) AS dateDDHHMMSS,
datetime({ date:dd, day: 28, hour: 10, minute: 10, second: 10, timezone:'Pacific/Honolulu' }) AS dateDDHHMMSSTimezone
dateHHMMSS | dateHHMMSSTimezone | dateDDHHMMSS | dateDDHHMMSSTimezone |
---|---|---|---|
1 row |
|||
|
|
|
|
Try this query live. none WITH date({year:1984, month:10, day:11}) AS dd RETURN datetime({date:dd, hour: 10, minute: 10, second: 10}) AS dateHHMMSS, datetime({date:dd, hour: 10, minute: 10, second: 10, timezone:'+05:00'}) AS dateHHMMSSTimezone, datetime({date:dd, day: 28, hour: 10, minute: 10, second: 10}) AS dateDDHHMMSS, datetime({date:dd, day: 28, hour: 10, minute: 10, second: 10, timezone:'Pacific/Honolulu'}) AS dateDDHHMMSSTimezone
The following query shows the various usages of datetime({time [, year, …, timezone]})
Query.
WITH time({ hour:12, minute:31, second:14, microsecond: 645876, timezone: '+01:00' }) AS tt
RETURN datetime({ year:1984, month:10, day:11, time:tt }) AS YYYYMMDDTime,
datetime({ year:1984, month:10, day:11, time:tt, timezone:'+05:00' }) AS YYYYMMDDTimeTimezone,
datetime({ year:1984, month:10, day:11, time:tt, second: 42 }) AS YYYYMMDDTimeSS,
datetime({ year:1984, month:10, day:11, time:tt, second: 42, timezone:'Pacific/Honolulu' }) AS YYYYMMDDTimeSSTimezone
YYYYMMDDTime | YYYYMMDDTimeTimezone | YYYYMMDDTimeSS | YYYYMMDDTimeSSTimezone |
---|---|---|---|
1 row |
|||
|
|
|
|
Try this query live. none WITH time({hour:12, minute:31, second:14, microsecond: 645876, timezone: '+01:00'}) AS tt RETURN datetime({year:1984, month:10, day:11, time:tt}) AS YYYYMMDDTime, datetime({year:1984, month:10, day:11, time:tt, timezone:'+05:00'}) AS YYYYMMDDTimeTimezone, datetime({year:1984, month:10, day:11, time:tt, second: 42}) AS YYYYMMDDTimeSS, datetime({year:1984, month:10, day:11, time:tt, second: 42, timezone:'Pacific/Honolulu'}) AS YYYYMMDDTimeSSTimezone
The following query shows the various usages of datetime({date, time [, year, …, timezone]})
; i.e. combining a Date and a Time value to create a single DateTime value:
Query.
WITH date({ year:1984, month:10, day:11 }) AS dd,
localtime({ hour:12, minute:31, second:14, millisecond: 645 }) AS tt
RETURN datetime({ date:dd, time:tt }) AS dateTime,
datetime({ date:dd, time:tt, timezone:'+05:00' }) AS dateTimeTimezone,
datetime({ date:dd, time:tt, day: 28, second: 42 }) AS dateTimeDDSS,
datetime({ date:dd, time:tt, day: 28, second: 42, timezone:'Pacific/Honolulu' }) AS dateTimeDDSSTimezone
dateTime | dateTimeTimezone | dateTimeDDSS | dateTimeDDSSTimezone |
---|---|---|---|
1 row |
|||
|
|
|
|
Try this query live. none WITH date({year:1984, month:10, day:11}) AS dd, localtime({hour:12, minute:31, second:14, millisecond: 645}) AS tt RETURN datetime({date:dd, time:tt}) as dateTime, datetime({date:dd, time:tt, timezone:'+05:00'}) AS dateTimeTimezone, datetime({date:dd, time:tt, day: 28, second: 42}) AS dateTimeDDSS, datetime({date:dd, time:tt, day: 28, second: 42, timezone:'Pacific/Honolulu'}) AS dateTimeDDSSTimezone
The following query shows the various usages of datetime({datetime [, year, …, timezone]})
Query.
WITH datetime({ year:1984, month:10, day:11, hour:12, timezone: 'Europe/Stockholm' }) AS dd
RETURN datetime({ datetime:dd }) AS dateTime,
datetime({ datetime:dd, timezone:'+05:00' }) AS dateTimeTimezone,
datetime({ datetime:dd, day: 28, second: 42 }) AS dateTimeDDSS,
datetime({ datetime:dd, day: 28, second: 42, timezone:'Pacific/Honolulu' }) AS dateTimeDDSSTimezone
dateTime | dateTimeTimezone | dateTimeDDSS | dateTimeDDSSTimezone |
---|---|---|---|
1 row |
|||
|
|
|
|
Try this query live. none WITH datetime({year:1984, month:10, day:11, hour:12, timezone: 'Europe/Stockholm'}) AS dd RETURN datetime({datetime:dd}) AS dateTime, datetime({datetime:dd, timezone:'+05:00'}) AS dateTimeTimezone, datetime({datetime:dd, day: 28, second: 42}) AS dateTimeDDSS, datetime({datetime:dd, day: 28, second: 42, timezone:'Pacific/Honolulu'}) AS dateTimeDDSSTimezone
datetime()
returns the DateTime value at the specified number of seconds or milliseconds from the UNIX epoch in the UTC time zone.
Conversions to other temporal instant types from UNIX epoch representations can be achieved by transforming a DateTime value to one of these types.
Syntax: datetime({ epochSeconds | epochMillis })
Returns:
A DateTime. |
Arguments:
Name | Description |
---|---|
|
|
|
A numeric value representing the number of seconds from the UNIX epoch in the UTC time zone. |
|
A numeric value representing the number of milliseconds from the UNIX epoch in the UTC time zone. |
Considerations:
|
Query.
RETURN datetime({ epochSeconds:timestamp()/ 1000, nanosecond: 23 }) AS theDate
theDate |
---|
1 row |
|
Try this query live. none RETURN datetime({epochSeconds:timestamp() / 1000, nanosecond: 23}) AS theDate
Query.
RETURN datetime({ epochMillis: 424797300000 }) AS theDate
theDate |
---|
1 row |
|
Try this query live. none RETURN datetime({epochMillis: 424797300000}) AS theDate
datetime.truncate()
returns the DateTime value obtained by truncating a specified temporal instant value at the nearest preceding point in time at the specified component
boundary (which is denoted by the truncation unit passed as a parameter to the function).
In other words, the DateTime returned will have all components that are less significant than the specified truncation unit set to their default values.
It is possible to supplement the truncated value by providing a map containing components which are less significant than
the truncation unit.
This will have the effect of overriding the default values which would otherwise have been set for these less significant components.
For example, day
— with some value x
— may be provided when the truncation unit is year
in order to ensure the returned value has the day set to x
instead of the default day (which is 1
).
Syntax: datetime.truncate(unit, temporalInstantValue [, mapOfComponents ])
Returns:
A DateTime. |
Arguments:
Name | Description |
---|---|
|
A string expression evaluating to one of the following: { |
|
An expression of one of the following types: {DateTime, LocalDateTime, Date}. |
|
An expression evaluating to a map containing components less significant than |
Considerations:
|
The time zone of |
If |
If |
Any component that is provided in |
Any component that is not contained in |
If |
Query.
WITH datetime({ year:2017, month:11, day:11, hour:12, minute:31, second:14, nanosecond: 645876123, timezone: '+03:00' }) AS d
RETURN datetime.truncate('millennium', d, { timezone:'Europe/Stockholm' }) AS truncMillenium,
datetime.truncate('year', d, { day:5 }) AS truncYear,
datetime.truncate('month', d) AS truncMonth,
datetime.truncate('day', d, { millisecond:2 }) AS truncDay,
datetime.truncate('hour', d) AS truncHour,
datetime.truncate('second', d) AS truncSecond
truncMillenium | truncYear | truncMonth | truncDay | truncHour | truncSecond |
---|---|---|---|---|---|
1 row |
|||||
|
|
|
|
|
|
Try this query live. none WITH datetime({year:2017, month:11, day:11, hour:12, minute:31, second:14, nanosecond: 645876123, timezone: '+03:00'}) AS d RETURN datetime.truncate('millennium', d, {timezone:'Europe/Stockholm'}) AS truncMillenium, datetime.truncate('year', d, {day:5}) AS truncYear, datetime.truncate('month', d) AS truncMonth, datetime.truncate('day', d, {millisecond:2}) AS truncDay, datetime.truncate('hour', d) AS truncHour, datetime.truncate('second', d) AS truncSecond