You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/cosmos-db/working-with-dates.md
+6-4Lines changed: 6 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ ms.service: cosmos-db
5
5
author: SnehaGunda
6
6
ms.author: sngun
7
7
ms.topic: conceptual
8
-
ms.date: 03/03/2020
8
+
ms.date: 04/03/2020
9
9
---
10
10
# Working with Dates in Azure Cosmos DB
11
11
@@ -15,7 +15,9 @@ In addition to the basic types, many applications need the DateTime type to repr
15
15
16
16
## Storing DateTimes
17
17
18
-
Azure Cosmos DB supports JSON types such as - string, number, boolean, null, array, object. It does not directly support a DateTime type. Currently, Azure Cosmos DB doesn't support localization of dates. So, you need to store DateTimes as strings. The recommended format for DateTime strings in Azure Cosmos DB is `YYYY-MM-DDThh:mm:ss.sssZ` which follows the ISO 8601 UTC standard. It is recommended to store all dates in Azure Cosmos DB as UTC. Converting the date strings to this format will allow sorting dates lexicographically. If non-UTC dates are stored, the logic must be handled at the client-side. To convert a local DateTime to UTC, the offset must be known/stored as a property in the JSON and the client can use the offset to compute UTC DateTime value.
18
+
Azure Cosmos DB supports JSON types such as - string, number, boolean, null, array, object. It does not directly support a DateTime type. Currently, Azure Cosmos DB doesn't support localization of dates. So, you need to store DateTimes as strings. The recommended format for DateTime strings in Azure Cosmos DB is `YYYY-MM-DDThh:mm:ss.fffffffZ` which follows the ISO 8601 UTC standard. It is recommended to store all dates in Azure Cosmos DB as UTC. Converting the date strings to this format will allow sorting dates lexicographically. If non-UTC dates are stored, the logic must be handled at the client-side. To convert a local DateTime to UTC, the offset must be known/stored as a property in the JSON and the client can use the offset to compute the UTC DateTime value.
19
+
20
+
Range queries with DateTime strings as filters are only supported if the DateTime strings are all in UTC and the same length. In Azure Cosmos DB, the [GetCurrentDateTime](sql-query-getcurrentdatetime.md) system function will return the current UTC date and time ISO 8601 string value in the format: `YYYY-MM-DDThh:mm:ss.fffffffZ`.
19
21
20
22
Most applications can use the default string representation for DateTime for the following reasons:
21
23
@@ -41,7 +43,7 @@ For example, the following snippet stores an `Order` object containing two DateT
41
43
{
42
44
Id="09152014101",
43
45
OrderDate=DateTime.UtcNow.AddDays(-30),
44
-
ShipDate=DateTime.UtcNow.AddDays(-14),
46
+
ShipDate=DateTime.UtcNow.AddDays(-14),
45
47
Total=113.39
46
48
});
47
49
```
@@ -70,7 +72,7 @@ The SQL .NET SDK automatically supports querying data stored in Azure Cosmos DB
70
72
Translated to the following SQL statement and executed on Azure Cosmos DB:
71
73
72
74
```sql
73
-
SELECT*FROM root WHERE (root["ShipDate"] >="2016-12-18T21:55:03.45569Z")
75
+
SELECT*FROM root WHERE (root["ShipDate"] >="2014-09-30T23:14:25.7251173Z")
74
76
```
75
77
76
78
You can learn more about Azure Cosmos DB's SQL query language and the LINQ provider at [Querying Cosmos DB in LINQ](sql-query-linq-to-sql.md).
0 commit comments