cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
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
Highlighted
Community Support
Community Support

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.

View solution in original post

6 REPLIES 6
Highlighted
Community Support
Community Support

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.
Highlighted
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

Highlighted
Community Support
Community Support

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.

View solution in original post

Highlighted
Super User
Super User

Re: How to filter SQL Server records by date?

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

Frequent Visitor

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())
Highlighted
New Member

Re: How to filter SQL Server records by date?

how to use that if i want to compare hh mm and ss ?

Helpful resources

Announcements
firstImage

Super User Program Update

Three Super User rank tiers have been launched!

firstImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

firstImage

New & Improved Power Automate Community Cookbook

We've updated and improved the layout and uploading format of the Power Automate Cookbook!

thirdimage

Power Automate Community User Group Member Badge

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

Top Solution Authors
Users online (3,935)