Showing results for 
Search instead for 
Did you mean: 

date related filter query to SQL database

I could not get the expected results when using Get Rows and Filter Query on date related fields. However Filter Query works with String or ID fields.


I stored two dates (DateFrom and DateTo) in the database, and to troubleshoot, I later changed to datetime. Database is in Azure SQL, connected using on premise gateway.  The data itself does not have time and only date. 


I tried all the following filter query for DateFrom and DateTo, and all cases except the last find no records. 

1) Construct a new string variable that contains year, month or day function separately. This approach of creating a string can spin the head very quickly using dynamic variables from earlier flow steps.  

day(DateFrom) eq day(2019-12-02T00:00:00Z) and month(DateFrom) eq month(2019-12-02T00:00:00Z) and year(DateFrom) eq year(2019-12-02T00:00:00Z) and day(DateTo)   eq day(2019-12-06T00:00:00Z) and month(DateTo)   eq month(2019-12-06T00:00:00Z) and year(DateTo) eq year(2019-12-06T00:00:00Z)


In addition, day, month and year are not functions available in Flow, so can you enable them if using those functions on the dynamic variables is required to construct the Filter Query instead of using variables as date directly as below alternatives.    


2) Without quote for actual dates 
DateFrom eq 2019-12-02T00:00:00Z and DateTo eq 2019-12-06T00:00:00Z
3) With quote
DateFrom eq '2019-12-02T00:00:00Z' and DateTo eq '2019-12-06T00:00:00Z'
4) Without time, quoted
DateFrom eq '2019-12-02' and DateTo eq '2019-12-06'
5) Without time, slashed, quoted
DateFrom eq '2019/12/02' and DateTo eq '2019/12/06'
6) Without time, slashed, without leading zero for day, quoted
DateFrom eq '2019/12/2' and DateTo eq '2019/12/6'
7) With datetime and does not pass 
DateFrom eq datetime'2019-12-02T00:00:00Z' and DateTo eq datetime'2019-12-06T00:00:00Z'

😎 With integer as below but error message said The $filter expression must evaluate to a single boolean value. I do have many rows with the same DateFrom and hope to get them back as a group of rows. 

day([DateFrom]) eq 2 and month([DateFrom]) eq 12 and year([DateFrom]) eq 2019

Hope it is easier, and I found other posts in the community about the difficulty with date or datetime fields. Thanks. 


Helpful resources

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Power Automate Designer Feedback_carousel.jpg

Help make Flow Design easier

Are you new to designing flows? What is your biggest struggle with Power Automate Designer? Help us make it more user friendly!

Top Solution Authors
Top Kudoed Authors
Users online (1,837)