Skip to main content

Notifications

Power Apps - Building Power Apps
Answered

Problem with the Today() function in a Filter expression

Posted on by 55
Building a canvas app, with Dynamics 365 (Dataverse) as my source. In my gallery on the main page, I added a search requirement :
 'Start Date' < Today()  
 'Start Date' < Today()  
Both of those seem to work fine; I get the results I expected.  The first one gives past Start Date entries and the second one gives future Start Date entries.
 
But what I really want is to do a search where the Start Date field is specifically greater than 30 days ago, so I entered 
'Start Date' > Today() - 30
This should give me results where Start Date is later than 30 days ago, on up to the present and future dates as well.  This does not work at all.
If this helps, both the ">" and the "-" symbols have a red squiggly line under them indicating there is something wrong; the squiggle is not under the "<" or ">" in those original statements above.  The squiggle only appears when I use the "-30" part of the expression.
 
Even more oddly, when I add an upper limit:
'Start Date' < Today() + 30
the squiggles do NOT appear in the second phrase, no matter which order I put them in.  So whether I enter one or the other below...
 'Start Date' < Today() + 30, 'Start Date' > Today() 30
 'Start Date' > Today() 30, 'Start Date' < Today() + 30
 
...in both those lines, the first expression has the squiggles and the second expression does not.
And in both cases, I get no results at all.
 
If it helps to see the entire line, here it is, placed into the "Items" field for the gallery:
Filter('House Events', SearchInputBox.Text in 'Event Description', 'Start Date' > Today()-30, 'Start Date' < Today() + 30)
 
I would really appreciate any suggestion you may have.  
 
As with many things regarding computers, the answer is easy, but not remotely intuitive.
 
 
  • WillBeeSea Profile Picture
    WillBeeSea 55 on at
    Problem with the Today() function in a Filter expression
    Thank you Mark Nanneman! 
    That is exactly what I needed.  I had tried DateAdd() before, but I messed up the syntax.
  • Verified answer
    Mark Nanneman Profile Picture
    Mark Nanneman 329 on at
    Problem with the Today() function in a Filter expression
    You need to use the DataAdd() function to get past or future times.
     
    //future
    DateAdd
    (Today(),30,TimeUnit.Days)
     
    //past
    DateAdd(Today(),-30,TimeUnit.Days)
    If this helped you, please click "Does this answer your question" and give it a like to help others in the community (+ close the ticket)!

    Power Platform Developer | LinkedIn: Mark Nanneman | Blog: Power Stuff  | YouTube: Mark's Power Stuff  | Buy me a coffee

     

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

November 2024 Newsletter…

November 2024 Community Newsletter…

Community Update Oct 28…

Power Platform Community Update…

Tuesday Tip #7 Community Profile Tips…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 143,487

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 64,014

Leaderboard