cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Super User
Super User

How to filter SQL Server records by date?

What's the correct syntax to filter a 'get rows' action by date?

 

For example, I have a SQL Server data source with a datetime column called DateOfBirth. My 'get rows' action returns 2 records. The screenshot below shows one of those records.

 

row1.PNG

 

I then added the following OData filter expression.

 

DateOfBirth lt '2017-01-01'

 

I would expect this to return both records because the dates of birth values on all records are less than 01-01-2017. However, this expression returns 0 rows, as shown in the screenshot.

 

row2.PNG

 

I tried all the date fomats I could think of, including UTC. I also tried prefixing the value with datetime, as shown here:

 

https://msdn.microsoft.com/en-us/library/hh169248(v=nav.90).aspx

 

This technqiue failed with the following error:

 

Unrecognized 'Edm.String' literal 'datedatetime'2010-01-25T02:13:40.1374695Z'' at '15' in 'DateOfBirth lt datedatetime'2010-01-25T02:13:40.1374695Z''.\r\n     inner exception: Unrecognized 'Edm.String' literal 'datedatetime'2010-01-25T02:13:40.1374695Z'' at '15' in 'DateOfBirth lt datedatetime'2010-01-25T02:13:40.1374695Z''

 

Can someone explain what might be going wrong here? Thanks. 

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: How to filter SQL Server records by date?

Hi @timl,

 

An update here:

Using the following format should make it work to filter with DateTime column in SQL Get Rows action.

Year(date2Datetime) ge 2017 and month(date2Datetime) ge 7 and day(date2Datetime) ge 1

 

 

35.PNG

 

Regards,

Michael

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
5 REPLIES 5
Community Support Team
Community Support Team

Re: How to filter SQL Server records by date?

Hi @timl,

 

Thanks for the feedback.

I think the filter query won't work should be the time string format issue, but currently it is not possible for me to figure that out.

I will send out feedback on this part to confirm the correct format.

Further, Filter query under SQL Server Get Rows Action works with Char and number type, a note is when working with number type, there is no need to add the single quotes.

Please add a filter Array Action after the Get Rows Action, then use the condition to filter the date.

Using FormatDateTime () function incroduced under workflow Definition Language.

 

Regards,

Michael

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Super User
Super User

Re: How to filter SQL Server records by date?

Hi Michael,

 

Thanks for your reply. I was hoping not to use the 'Filter Array Action' to avoid selecting all the records from my table, but I guess that's not too much of a problem for smaller tables.

 

The clarification about how the Get Rows Action works only with char and number types is useful.

 

Tim

Community Support Team
Community Support Team

Re: How to filter SQL Server records by date?

Hi @timl,

 

An update here:

Using the following format should make it work to filter with DateTime column in SQL Get Rows action.

Year(date2Datetime) ge 2017 and month(date2Datetime) ge 7 and day(date2Datetime) ge 1

 

 

35.PNG

 

Regards,

Michael

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Super User
Super User

Re: How to filter SQL Server records by date?

Hi Michael, thanks for the update. Yes, that works much better!

hifni
Level: Powered On

Re: How to filter SQL Server records by date?

Your solution worked great; However, if I need to get the current date and how can use it with utcNow() function?

 

I tried below formula but it did not work well.

 

Year(date2Datetime) ge Year(utcNow())

Helpful resources

Announcements
firstImage

Microsoft Business Applications Virtual Launch Event

Watch the event on demand for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 Release Wave 2 Plan

Power Platform 2019 Release Wave 2 Plan

Features releasing from October 2019 through March 2020.

thirdimage

Flow Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Flow Community Video Gallery!

Users Online
Currently online: 411 members 4,892 guests
Please welcome our newest community members: