Do Azure digital twins support date time query?

I am working with Azure digital twins where we ahve a property called 'TimeOfEvent', the property is being updated together with other properties. Now I would like to query the Digital Twin to find all twins that have been updated after a serten time and date.

Following the documentation [1]https://learn.microsoft.com/en-us/azure/digital-twins/how-to-query-graph) 2: It the query string would look something like this. SELECT * FROM DIGITALTWINS Twins WHERE Twins.TimeOfEvent > '06/07/2023 08:12:57' But nothing is retured. Is this supported at all or do I need to format TimeOfEvent in another way?

Thanks in advance!

Tried multipe different query strings with no success using the ADT explorer. The result I want is data from twins that has been updated after a specific time and date.

Upvotes: 0

Views: 231

Answers (1)

Sampath
Sampath

Reputation: 3684

AFAIK One of the reason the updated data you are sending will update at the point of a given time and if the new event is triggered for data the time of the Updated time will also change.

Since while usingWHERE Twins.TimeOfEvent >(or) < (or) = '06/07/2023 08:12:57' . Where is used to display the data within Condition? Since the data and time also change.

  • It showing as Empty.

enter image description here

  • Updated sample Tags with TimeofEvents with reference SO and EventTrigger.

Sample Code:

twin.Properties.Reported["TimeOfEvent"] = DateTime.UtcNow;
await registryManager.UpdateTwinAsync(twin.DeviceId, twin, twin.ETag);

               
log.LogInformation
("Device twin updated.");
               
            }
            
  • The One of solution is to Register the TimeofEvents like Properties like this. Also Check the formate of the data after upadting.

Sample Input:

{
  "@id": "dtmi:example:Room;1",
  "@type": "Interface",
  "displayName": "Room",
  "contents": [
    {
      "@type": "Property",
      "name": "Temperature",
      "schema": "double"
    },
    {
      "@type": "Property",
      "name": "Humidity",
      "schema": "double"
    },
{
      "@type": "Property",
      "name": "TimeOfEvent",
      "schema": "DateTime"
    }
  ],
  "@context": "dtmi:dtdl:context;2"
}
 

enter image description here

Upvotes: 0

Related Questions