'How to query cosmos records by today date with c#?
I want to get all records where the datetime value is today.
What is the correct query string when using the c# sdk?
The property is:
public DateTime DueDate { get; set; }
Not working:
String today = DateTime.Today.ToString();
string qs = "SELECT * FROM c where c.dueDate='"+today +"'
In cosmos db the json looks like this:
"dueDate": "2022-04-14T15:28:30.5919691+02:00"
Solution 1:[1]
var today = DateTime.Today.ToString("yyyy-MM-ddTHH\\:mm\\:ss.fffffffzzz");
var tomorrow = DateTime.Today.AddDays(1).ToString("yyyy-MM-ddTHH\\:mm\\:ss.fffffffzzz");
string qs = "SELECT * FROM c where c.dueDate >='"+today +"' AND c.dueDate <='"+tomorrow +"'
or
string qs = "SELECT * FROM c where c.dueDate BETWEEN '"+today +"' AND '"+tomorrow +"'";
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
