'Azure Cosmos DB Date Query as string not working

Basically its just query get operation in azure cosmos db based on machine id and datetime. I am really stuck on querying in cosmos based on datetime.The same query I am able to run and get the result on azure portal.But code wise I am not getting the result.

A few more details:

SELECT *
FROM c
WHERE c.IoTHub.ConnectionDeviceId IN ('hub20') AND c.MACHINE_ID = 'TAP_20' AND (c.EventEnqueuedUtcTime >= '2021-02-03T10:40:42.5180000Z' AND c.EventEnqueuedUtcTime <= '2021-02-03T10:40:42.5180000Z')
QueryDefinition queryDefinition = new QueryDefinition(sqlQueryText);
FeedIterator<dynamic> queryResultSetIterator = container.GetItemQueryIterator<dynamic>(queryDefinition);
FeedResponse<dynamic> currentResultSet;
while (queryResultSetIterator.HasMoreResults)
{
    currentResultSet = await queryResultSetIterator.ReadNextAsync();
}     

I am able to get all the data till MACHINE_ID but as soon as I apply c.EventEnqueuedUtcTime condition. I am not able to get the data.I tried every possible solution.c.EventEnqueuedUtcTime value we are getting as a string and also in database it is saved as string as you can see in the image.

{
    "MESSAGE_GROUP_ID": "24c9e3ad-4fd6-4abb-88d8-eafb9060884e",
    "TYPE": "Gauges",
    "MACHINE_ID": "TAP_20",
    "Gauges": {
        "OVERRIDE": 85.8
    },
    "EventProcessedUtcTime": "2021-02-03T10:41:48.0493615Z",
    "PartitionId": 3,
    "EventEnqueuedUtcTime": "2021-02-03T10:40:42.5180000Z",
    "IoTHub": {
        "MessageId": "498b7df3-55e6-4b3f-a18e-698fd991e526",
        "CorrelationId": null,
        "ConnectionDeviceId": "hub20",
        "ConnectionDeviceGenerationId": "637332663098221999",
        "EnqueuedTime": "2021-02-03T10:41:11.2570000Z"
    },
    "id": "498b7df3-55e6-4b3f-a18e-698fd991e526"
}

enter image description here

Any lead will be appreciated. Thanks



Solution 1:[1]

Thank you user2911592 for sharing the resolution steps. Posting them as answer to help other community members.

Initially the query/code was saved incorrectly using casting. Fixing the same resolved the issue.

user2911592: feel free to add furthermore details.

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 MadhurajVadde-MT