0

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.

1 Answers1

0

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

Sampath
  • 810
  • 2
  • 2
  • 13
  • Im sorry for beign not clear in my question or I just might not understand the awnser. So we have the Property TimeOfEvent, that is being updated form our IOT device. Using query API is there a way to find fetch all twins that was updated after a serten date and time by reading the TimeOfEvent. – Samuel Engström Jun 08 '23 at 17:40
  • if have Time of Event Property, the query will be `SELECT * FROM digitaltwins T where T.TimeofEvent>`.Also, check the format of the data after [upadting](https://i.imgur.com/0xeLa7e.png). according to my input for more details refer [to this](https://www.youtube.com/watch?v=YBwraf72BKI) and [MSDOC](https://learn.microsoft.com/en-us/samples/azure-samples/digital-twins-explorer/digital-twins-explorer/?WT.mc_id=docs-azuredevtipsvideo-azureappsdev). – Sampath Jun 09 '23 at 01:27
  • I know how to use the query for numerical and string values. But I still do not get if it is even possible to have a Date Time parameter to do operaions on. Such as greater or less then (< > ). Or if my problem is that the Date Time needs to be have a format other then '2023-06-14 12:06:58.939' – Samuel Engström Jun 14 '23 at 12:14
  • we can use " =" and Yes, it is possible to perform operations on DateTime parameters in various programming languages or query languages. However, the availability and syntax for such operations can depend on the specific language or database system you are using. In many programming languages, you can compare DateTime values using greater than (>) and less than (<) operators. These operators allow you to compare two DateTime values and determine if one is greater than or less than the other. – Sampath Jun 14 '23 at 12:18