DateTimeFromParts (NoSQL query)

APPLIES TO: NoSQL

Returns a date and time string value constructed from input numeric values for various date and time parts.

Syntax

DateTimeFromParts(<numeric_year>, <numeric_month>, <numeric_day> [, <numeric_hour>]  [, <numeric_minute>]  [, <numeric_second>] [, <numeric_second_fraction>])

Arguments

Description
numeric_year A positive numeric integer value for the year. This argument is in the ISO 8601 format yyyy.
numeric_month A positive numeric integer value for the month. This argument is in the ISO 8601 format mm.
numeric_day A positive numeric integer value for the day. This argument is in the ISO 8601 format dd.
numeric_hour (Optional) An optional positive numeric integer value for the hour. This argument is in the ISO 8601 format hh. If not specified, the default value is 0.
numeric_minute (Optional) An optional positive numeric integer value for the minute. This argument is in the ISO 8601 format mm. If not specified, the default value is 0.
numeric_second (Optional) An optional positive numeric integer value for the second. This argument is in the ISO 8601 format ss. If not specified, the default value is 0.
numeric_second_fraction (Optional) An optional positive numeric integer value for the fractional of a second. This argument is in the ISO 8601 format fffffffZ. If not specified, the default value is 0.

Note

For more information on the ISO 8601 format, see ISO 8601.

Return types

Returns a UTC date and time string in the ISO 8601 format YYYY-MM-DDThh:mm:ss.fffffffZ.

Examples

The following example uses various combinations of the arguments to create date and time strings. This example uses the date and time April 20, 2017 13:15 UTC.

SELECT VALUE {
    constructMinArguments: DateTimeFromParts(2017, 4, 20),
    constructMinEquivalent: DateTimeFromParts(2017, 4, 20, 0, 0, 0, 0),
    constructAllArguments: DateTimeFromParts(2017, 4, 20, 13, 15, 20, 3456789),
    constructPartialArguments: DateTimeFromParts(2017, 4, 20, 13, 15),
    constructInvalidArguments: DateTimeFromParts(-2000, -1, -1)
}
[
  {
    "constructMinArguments": "2017-04-20T00:00:00.0000000Z",
    "constructMinEquivalent": "2017-04-20T00:00:00.0000000Z",
    "constructAllArguments": "2017-04-20T13:15:20.3456789Z",
    "constructPartialArguments": "2017-04-20T13:15:00.0000000Z"
  }
]

Remarks

  • If the specified integers would create an invalid date and time, the function returns undefined.