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

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
v-micsh-msft
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.

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

v-micsh-msft
Community Support
Community Support

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

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

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())

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

Helpful resources

Announcements
MPA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

Top Solution Authors
Users online (57,140)