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

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

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

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

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

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

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

Highlighted

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

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

Helpful resources

Announcements
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

Users online (8,625)