cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
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
Anonymous
Not applicable

@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

5 REPLIES 5
v-xida-msft
Community Support
Community Support

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.
Anonymous
Not applicable

@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

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

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.

Hi All,

 

This seems to be case sensitive and does not work with time (not sure why).  A Date field in SQL works, and DateTime/Datetime2 field does not.

 

Lots of testing to get to this point, but if you can split your date and time, you may be able to use this.

 

Tested with SQL16 on prem.

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 (71,792)