Condividi tramite


DATETIMEPART - Linguaggio di query in Cosmos DB (in Azure e Fabric)

La DATETIMEPART funzione restituisce il valore della parte di data e ora specificata per la data e l'ora specificate.

Sintassi

DATETIMEPART(<date_time_part>, <date_time>)

Arguments

Description
date_time_part Stringa che rappresenta una parte di una specifica del formato di data ISO 8601. Questa parte viene utilizzata per indicare quale aspetto della data estrarre e restituire.
date_time Stringa di data e ora UTC (Coordinated Universal Time) nel formato YYYY-MM-DDThh:mm:ss.fffffffZISO 8601 .

Tipi restituiti

Restituisce un valore numerico che è un numero intero positivo.

Esempi

Questa sezione contiene esempi di come usare questo costrutto di linguaggio di query.

Estrarre parti di data e ora

In questo esempio la DATETIMEPART funzione viene usata per estrarre anno, mese, giorno, ora, minuto, secondo, millisecondo, microsecondo e nanosecondo da una data.

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
  }
]

Osservazioni:

  • Questa funzione non usa l'indice.
  • Il formato di data ISO 8601 specifica parti di data e ora valide da utilizzare con questa funzione: | | Formato | | | --- | --- | | Year | year, yyyy, yy | | Month | month, mm, | m | Giorno | day, dd, d | | Hour | hour, hh | | Minute | minute, mi, , n | | Secondo | second, ss, s | | Millisecondo | millisecond, ms | | Microsecondo | microsecond, mcs | | Nanosecondo | nanosecond, ns |
  • Questa funzione restituisce undefined per questi motivi:
    • La parte di data e ora specificata non è valida.
    • La data e l'ora non sono una stringa di data e ora ISO 8601 valida.