web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / How to filter SQL Serv...
Power Automate
Answered

How to filter SQL Server records by date?

(0) ShareShare
ReportReport
Posted on by 37,420 Super User 2026 Season 2

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. 

Categories:
  • v-micsh-msft Profile Picture
    Microsoft Employee on at

    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

  • timl Profile Picture
    37,420 Super User 2026 Season 2 on at

    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

  • Verified answer
    v-micsh-msft Profile Picture
    Microsoft Employee on at

    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

  • timl Profile Picture
    37,420 Super User 2026 Season 2 on at

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

  • HN-04060819-0 Profile Picture
    46 on at

    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())
  • mudasirahmed Profile Picture
    2 on at

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

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Automate

#1
11manish Profile Picture

11manish 298 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 289

#3
Henil Profile Picture

Henil 125

Last 30 days Overall leaderboard