web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / OData datetime based F...
Power Apps
Answered

OData datetime based Filtering still broken?

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

This is similar to this Q:-
https://powerusers.microsoft.com/t5/Building-Flows/ICM-Connector-What-is-the-correct-syntax-for-time-based-searches
Is this still the situation? That OData cannot pass a datetime to a query?

This is really clunky.

I need my query to have a datetime filter, otherwise I cant get it to return as the data set being queried is far too large and it times out or is throttled.
So I cannot use the suggested solution above. As it would fail to get me any result set to subsequently filter on.

This has to be a common use case that this lack of functionality is breaking?

FWIW, here's my error:-
"message": "Invalid options specified in OData query. Unrecognized 'Edm.String' literal 'datetime'2023-10-30T10:23:56'' at '15' in 'CreatedDate gt datetime'2023-10-30T10:23:56' and OwningTenantName eq 'redacted' and State eq 'ACTIVE' and Title eq 'Redacted''."

In this case, the datetime is populated into a string variable in a prior step and passed to the Search Incidents (advanced) step.

The variable is calculated via this formula:

concat('datetime', '''', formatDateTime(addDays(utcNow(), -7), 'yyyy-MM-ddThh:mm:ss'), '''')

The  ICM documentation specifies a particular format, which this matches,  so that is not the problem.

https://icmdocs.azurewebsites.net/developers/IncidentSearch.html#sample-queries

Categories:
I have the same question (0)
  • Verified answer
    Hassan_SZ_365 Profile Picture
    542 on at

    Hi,

    OData does support filtering by date and time, but the correct syntax can be a bit finicky. You must ensure that the datetime value is formatted according to the OData version that the API expects. Generally, in OData v4, you don't need the datetime keyword anymore.

    If you're encountering issues, it's possible there might be a problem with the syntax or the API you are working with might not fully support the OData datetime filter.

    Your error message seems to indicate that the datetime literal is not being recognized. In OData v4, the correct format for a datetime filter in a URL should look like this:

     

    ...&$filter=CreatedDate gt 2023-10-30T10:23:56Z

     

    Here's a simplified step you might try:

    1. Ensure that the API you're using supports the OData datetime filter.
    2. Confirm whether the API uses OData v4 or an earlier version, as the syntax differs.
    3. Correct the syntax of the datetime filter according to the version of OData.

    For an OData v4 filter, you can try formatting your variable like this:

     

    formatDateTime(addDays(utcNow(), -7), 'yyyy-MM-ddTHH:mm:ssZ')

     

    And then in your OData filter:

     

    $filter=CreatedDate gt 2023-10-30T10:23:56Z

     

    If the API requires single quotes around the datetime, make sure they're properly included:

     

    $filter=CreatedDate gt '2023-10-30T10:23:56Z'

     

    Be mindful of the time zone information (Z indicates Zulu/UTC time). If the API expects the local time, you'll need to adjust the time zone accordingly. Also, note the use of HH for 24-hour time formatting, which could be a potential issue if hh is used instead.

    If these steps don't resolve the issue, you might need to consult the API documentation or reach out to the API provider for more specific guidance on the correct datetime filter syntax for their service.


    Best Regards,

    Hassan Raza

  • davidBlount Profile Picture
    Microsoft Employee on at

    Thanks Hassan,
    To confirm as of the time of typing this the formatting of the datetime value to the query as follows works with querying ICM via OData.

    CreatedDate gt '2023-10-30T15:43:35Z' and OwningTenantName eq 'redacted' and State eq 'ACTIVE' and Title eq 'Redacted'

    Also, FWIW, it was using this variable initialization prior to the query, creating a variable called sevenDaysAgo

    concat(formatDateTime(addDays(utcNow(), -7), 'yyyy-MM-ddTHH:mm:ss'), 'Z')

    And the actual query in logic app is declared then like so (code view snippet):-

     "method": "get",
     "headers": {
     "icm-path": "Incidentapi/incidents?$filter=<incidentId>",
     "icm-path-value": "CreatedDate gt @{variables('sevenDaysAgo')} and OwningTenantName eq 'Redacted' and State eq 'ACTIVE' and Title eq 'Redacted'"
     },

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 577

#2
WarrenBelz Profile Picture

WarrenBelz 440 Most Valuable Professional

#3
Haque Profile Picture

Haque 308

Last 30 days Overall leaderboard