|
1 | 1 | --- |
2 | | -title: GetCurrentDateTime in Azure Cosmos DB query language |
3 | | -description: Learn about SQL system function GetCurrentDateTime in Azure Cosmos DB. |
4 | | -author: seesharprun |
| 2 | +title: GetCurrentDateTime |
| 3 | +titleSuffix: Azure Cosmos DB for NoSQL |
| 4 | +description: An Azure Cosmos DB for NoSQL system function that returns an ISO 8601 date and time value. |
| 5 | +author: jcodella |
| 6 | +ms.author: jacodel |
| 7 | +ms.reviewer: sidandrews |
5 | 8 | ms.service: cosmos-db |
6 | 9 | ms.subservice: nosql |
7 | | -ms.topic: conceptual |
8 | | -ms.date: 02/03/2021 |
9 | | -ms.author: sidandrews |
10 | | -ms.reviewer: jucocchi |
11 | | -ms.custom: query-reference, ignite-2022 |
| 10 | +ms.topic: reference |
| 11 | +ms.date: 07/19/2023 |
| 12 | +ms.custom: query-reference |
12 | 13 | --- |
13 | | -# GetCurrentDateTime (Azure Cosmos DB) |
| 14 | + |
| 15 | +# GetCurrentDateTime (NoSQL query) |
| 16 | + |
14 | 17 | [!INCLUDE[NoSQL](../../includes/appliesto-nosql.md)] |
15 | 18 |
|
16 | 19 | Returns the current UTC (Coordinated Universal Time) date and time as an ISO 8601 string. |
17 | | - |
| 20 | + |
18 | 21 | ## Syntax |
19 | | - |
| 22 | + |
20 | 23 | ```sql |
21 | | -GetCurrentDateTime () |
| 24 | +GetCurrentDateTime() |
22 | 25 | ``` |
23 | 26 |
|
24 | 27 | ## Return types |
25 | | - |
26 | | -Returns the current UTC date and time ISO 8601 string value in the format `YYYY-MM-DDThh:mm:ss.fffffffZ` where: |
27 | | - |
28 | | -|Format|Description| |
29 | | -|-|-| |
30 | | -|YYYY|four-digit year| |
31 | | -|MM|two-digit month (01 = January, etc.)| |
32 | | -|DD|two-digit day of month (01 through 31)| |
33 | | -|T|signifier for beginning of time elements| |
34 | | -|hh|two-digit hour (00 through 23)| |
35 | | -|mm|two-digit minutes (00 through 59)| |
36 | | -|ss|two-digit seconds (00 through 59)| |
37 | | -|.fffffff|seven-digit fractional seconds| |
38 | | -|Z|UTC (Coordinated Universal Time) designator| |
39 | | - |
40 | | - For more information on the ISO 8601 format, see [ISO_8601](https://en.wikipedia.org/wiki/ISO_8601) |
41 | 28 |
|
42 | | -## Remarks |
43 | | - |
44 | | -GetCurrentDateTime() is a nondeterministic function. The result returned is UTC. Precision is 7 digits, with an accuracy of 100 nanoseconds. |
| 29 | +Returns the current UTC date and time string value in the **round-trip** (ISO 8601) format. |
45 | 30 |
|
46 | 31 | > [!NOTE] |
47 | | -> This system function will not utilize the index. If you need to compare values to the current time, obtain the current time before query execution and use that constant string value in the `WHERE` clause. |
| 32 | +> For more information on the round-trip format, see [.NET round-trip format](/dotnet/standard/base-types/standard-date-and-time-format-strings#the-round-trip-o-o-format-specifier). For more information on the ISO 8601 format, see [ISO 8601](https://wikipedia.org/wiki/ISO_8601). |
48 | 33 |
|
49 | 34 | ## Examples |
50 | | - |
51 | | -The following example shows how to get the current UTC Date Time using the GetCurrentDateTime() built-in function. |
52 | | - |
53 | | -```sql |
54 | | -SELECT GetCurrentDateTime() AS currentUtcDateTime |
55 | | -``` |
56 | | - |
57 | | - Here is an example result set. |
58 | | - |
59 | | -```json |
60 | | -[{ |
61 | | - "currentUtcDateTime": "2019-05-03T20:36:17.1234567Z" |
62 | | -}] |
63 | | -``` |
| 35 | + |
| 36 | +The following example shows how to get the current UTC date and time string. |
| 37 | + |
| 38 | +:::code language="sql" source="~/cosmos-db-nosql-query-samples/scripts/getcurrentdatetime/query.novalidate.sql" highlight="2"::: |
| 39 | + |
| 40 | +:::code language="json" source="~/cosmos-db-nosql-query-samples/scripts/getcurrentdatetime/result.novalidate.json"::: |
| 41 | + |
| 42 | +## Remarks |
| 43 | + |
| 44 | +- This function is nondeterministic. |
| 45 | +- The result returned is UTC (Coordinated Universal Time) with precision of seven digits and an accuracy of 100 nanoseconds. |
| 46 | +- This function doesn't use the index. |
| 47 | +- If you need to compare values to the current time, obtain the current time before query execution and use that constant string value in the `WHERE` clause. |
64 | 48 |
|
65 | 49 | ## Next steps |
66 | 50 |
|
67 | 51 | - [System functions Azure Cosmos DB](system-functions.yml) |
68 | | -- [Introduction to Azure Cosmos DB](../../introduction.md) |
| 52 | +- [`GetCurrentDateTimeStatic`](getcurrentdatetimestatic.md) |
0 commit comments