cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Anonymous
Not applicable

SQL Get Rows - Date Filter Between Two Dates

Hi All,

 

Read a few posts regarding this issue and havin the same problem.

 

My data looks like this:

1.PNG

Where MetricDate =  datetime data type in SQL Server.

 

I want to return 7 records between 2018-01-27 and 2018-02-02 so my SQL statement would be:

MetricDate  >= '2018-01-27' and  MetricDate  <= '2018-02-02'

 

However I cant get the ODATA filter query to work correctly and I have tried pulling out Year,Month and Day seperately as per other post.

 

I can get all of January and Feburary to return using:

Year(MetricDate) ge 2018 and Month(MetricDate) ge 1 and Month(MetricDate) le 2  

 

Adding the days in the following doesnt return any retuls:

Year(MetricDate) ge 2018 and Month(MetricDate) ge 1 and Month(MetricDate) le 2  and Day(MetricDate) ge 27 and Day(MetricDate) le 2

 

2.PNG

 

Ive also tried MetricDate ge datetime'2018-01-27' and MetricDate le datetime'2018-02-02'  which would be so much easier but get the following error: 

 

3.PNG

 

and i'm not sure why, what version of ODATA does FLOW use?

 

Any help on how to search between two dates using an ODATA filter would be massive help,  the point of this is to limit the records used as a data source (depending upon user date selections in the app) to pull into PowerApps  (due to the 500 record limitation), so i really need this to work.

 

I'm also using an On-Premises Gateway if info required.

 

Help please! 😄

 

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Anonymous
Not applicable

Re: SQL Get Rows - Date Filter Between Two Dates

@v-xida-msft

 

Many thanks for that detailed response.

 

It was very useful.

 

However as my date range is variable upon user select it could be for days,weeks,months even years. The solution would require to pull more records than needed.

 

I have implemented my own workaround and created an int column within my date where by my MetricDate is converted to int here, that way i can query between two int ranges in the ODATA filter and this is working as expected now.

 

Thanks again for your help.

View solution in original post

4 REPLIES 4
Highlighted
Community Support
Community Support

Re: SQL Get Rows - Date Filter Between Two Dates

Hi @jmc17,

 

The date time in SQL table would be converted into UTC format automatically in Microsoft Flow. The datatime column in my SQL table as below:6.JPG

The datatime column that Microsoft Flow get as below:7.JPG

 

I have made a test on my side and please take a try with the following workaround:

  • Add a proper trigger, here I use Flow Button trigger.
  • Add “Get rows” action, Filter Query field set to following formula:
Year(DueTime) ge 2018 and month(DueTime) ge 1 and day(DueTime) ge 27
  • Add “Get rows 2” action, specify same Table name with “Get rows” action, Filter Query set to following formula:
Year(DueTime) ge 2018 and month(DueTime) le 2 and day(DueTime) le 2
  • Add a “Compose” action, Inputs set to following formula:
union(body('Get_rows')?['value'],body('Get_rows_2')?['value'])

Image reference:8.JPG

 

9.JPG

Note: There is no OData query to filter records between two dates in one “Get rows” action of Microsoft Flow currently.

 

The flow works successfully as below:10.JPG

 

Best regards,

Kris

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted
Anonymous
Not applicable

Re: SQL Get Rows - Date Filter Between Two Dates

@v-xida-msft

 

Many thanks for that detailed response.

 

It was very useful.

 

However as my date range is variable upon user select it could be for days,weeks,months even years. The solution would require to pull more records than needed.

 

I have implemented my own workaround and created an int column within my date where by my MetricDate is converted to int here, that way i can query between two int ranges in the ODATA filter and this is working as expected now.

 

Thanks again for your help.

View solution in original post

Highlighted
New Member

Re: SQL Get Rows - Date Filter Between Two Dates

Hi Why don't you share your solution to others. i have the similar issue. when i use day(date) function in my filter query, which is not returning proper value all the time. 

 

in my filter query i am using the following 

Month(MODIFIED_DATE) ge 2

day(MODIFIED_DATE) ge 27

Highlighted
Frequent Visitor

Re: SQL Get Rows - Date Filter Between Two Dates

Thanks Kris

 

I got this working ...

year(TargetDate) le @{formatDateTime(addHours(utcNow(),1),'yyyy')} and
month(TargetDate) le @{formatDateTime(addHours(utcNow(),1),'MM')} and
day(TargetDate) le @{formatDateTime(addHours(utcNow(),1),'dd')} and
hour(TargetDate) le @{formatDateTime(addHours(utcNow(),1),'HH')}

 

Copy and past the above into the 'Filter Query' section as is. I had to add an extra hour to get the current time (UK GMT Summer time, clock madness), so change that as you see fit. Change 'le' to 'gt' or 'eq' depending on what you want to do.

 

This checks DB field date (datetime field) against the current time.


Change 'TargetDate' for whatever datetime field you are using.

 

by the way, don't try and check for minutes as that ws turning into a hit and miss ..... uumm .. unless i bracket it .. if you getting minutes working consistently, please update my code and let me know.

Helpful resources

Announcements
secondImage

August 2020 CYST Winners!

Check out the winners of the recent 'Can You Solve These?' community challenge!

thirdImage

Experience what's new for Power Automate

Join us for an in-depth look at the new Power Automate features and capabilities at the free Microsoft Business Applications Launch Event.

firstImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

thirdimage

Power Automate Community User Group Member Badge

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

Users online (3,619)