DateTimePart (NoSQL query)
APPLIES TO: NoSQL
Returns the value of the specified date and time part for the provided date and time.
Syntax
DateTimePart(<date_time_part> , <date_time>)
Arguments
Description | |
---|---|
date_time |
A Coordinated Universal Time (UTC) date and time string in the ISO 8601 format YYYY-MM-DDThh:mm:ss.fffffffZ . |
date_time_part |
A string representing a part of an ISO 8601 date format specification. This part is used to indicate which aspect of the date to extract and return. |
Note
For more information on the ISO 8601 format, see ISO 8601.
Return types
Returns a numeric value that is a positive integer.
Examples
The following example returns various parts of the date and time May 29, 2016 08:30 UTC.
SELECT VALUE {
getYear: DateTimePart("yyyy", "2016-05-29T08:30:00.1301617"),
getMonth: DateTimePart("mm", "2016-05-29T08:30:00.1301617"),
getDay: DateTimePart("dd", "2016-05-29T08:30:00.1301617"),
getHour: DateTimePart("hh", "2016-05-29T08:30:00.1301617"),
getMinute: DateTimePart("mi", "2016-05-29T08:30:00.1301617"),
getSecond: DateTimePart("ss", "2016-05-29T08:30:00.1301617"),
getMillisecond: DateTimePart("ms", "2016-05-29T08:30:00.1301617"),
getMicrosecond: DateTimePart("mcs", "2016-05-29T08:30:00.1301617"),
getNanosecond: DateTimePart("ns", "2016-05-29T08:30:00.1301617")
}
[
{
"getYear": 2016,
"getMonth": 5,
"getDay": 29,
"getHour": 8,
"getMinute": 30,
"getSecond": 0,
"getMillisecond": 130,
"getMicrosecond": 130161,
"getNanosecond": 130161700
}
]
Remarks
- This function returns
undefined
for these reasons:- The specified date and time part is invalid.
- The date and time isn't a valid ISO 8601 date and time string.
- The ISO 8601 date format specifies valid date and time parts to use with this function:
| | Format |
| --- | --- |
| Year |
year
,yyyy
,yy
| | Month |month
,mm
,m
| | Day |day
,dd
,d
| | Hour |hour
,hh
| | Minute |minute
,mi
,n
| | Second |second
,ss
,s
| | Millisecond |millisecond
,ms
| | Microsecond |microsecond
,mcs
| | Nanosecond |nanosecond
,ns
| - This function doesn't use the index.