Azure Logic App SQL ODATA Filter on Date

天涯浪子 提交于 2019-12-05 19:59:05

However, I can't for the life of me figure out how to implement that filter as part of the ODATA query.

I suppose you mean on the ODATA Query on the SQL Connector?

Can you try the following:

DateCreated lt @{addDays(utcNow(),-60)}

Based on the previous answer, you should try the same command :

DateCreated lt @{addDays(utcNow(),-60)}

But also, you must ensure that your data type, on the SQL side, must be a datetimeoffset.

Three solutions to do this :

  • Change the type of your field in your table,

  • Create a view and cast the field DateCreated to DATETIMEOFFSET CREATE VIEW [dbo].[myview] AS SELECT MyFields, ..., CAST(DateCreated AS DATETIMEOFFSET) AS DateCreated FROM MyTable

  • Create a store procedure with a DATETIMEOFFSET parameter, and convert the parameter to a DATETIME

If you can not change your SQL code, this piece of code is the solution :

year(DateCreated) lt year(@{addDays(utcNow(),-60)}) or (
    year(DateCreated) eq year(@{addDays(utcNow(),-60)}) and (
            month(DateCreated) lt month(@{addDays(utcNow(),-60)} or (
                month(DateCreated) eq month(@{addDays(utcNow(),-60)}
                ... <same thing for other date parts>
        )
    )
)

You have to compare each part of your date :

This is an interesting issue that sometimes shows up when dates, times, datetimes, and specific time zone come into play. Comparing a DateTimeZone to a date is problematic, because it might be less in arithmetic terms but only if the time zone matches... without that critical piece of information, these data types cannot be compared.

One alternative is to use the standard OData functions to retrieve parts of the data type. For example:

$filter = year(release_date) lt year(dtz)

Of course, you must be carful to ensure that you are implementing the correct logic with respect to timezone- but you are probably aware of that.

OData Reference : http://www.odata.org/documentation/odata-version-2-0/uri-conventions/

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!