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 Apps / Strange Bug in Gallery...
Power Apps
Answered

Strange Bug in Gallery when using DateDiff() in If statement

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

I have noticed this strange behavior.

What I am trying to do:

If DateFrom and DateTo is the same date show only one date if they are different show two dates with – in between them.

 

My setup:

 1.png

Formula of 1.:

2.png

If(
    DateDiff(ThisItem.DateFrom,ThisItem.DateTo,Days) = 0,
    ThisItem.DateFrom,
    ThisItem.DateFrom&" - "&ThisItem.DateTo
)



 

To test I put some extra fields

Formulas

2.

DateDiff(ThisItem.DateFrom,ThisItem.DateTo,Days)

3.

"DateFrom: "&ThisItem.DateFrom

4.

"DateTo: "&ThisItem.DateTo

5.

ThisItem.DateFrom&" - "&ThisItem.DateTo

 

Database structure (showing only fields in question):

CREATE TABLE VacationRequest (
    DateFrom date NOT NULL,
    DateTo date NOT NULL,
);

 

 

This is clearly a bug or am I missing something? I can reproduce this 100% of the time.

  1. Have a database with two date fields
  2. Create a gallery
  3. In text field write the following formula:
If(
    DateDiff(ThisItem.Date1,ThisItem.Date2,Days) = 0,
    ThisItem.Date1,
    ThisItem.Date1&" - "&ThisItem.Date2
)

 

I have also tested this with different table where dates were datetime variable and got same results.

 

Crazily enough if you play with formula and reverse it, it works:

3.png

If(
    DateDiff(ThisItem.DateFrom,ThisItem.DateTo,Days) <> 0,
    ThisItem.DateFrom&" - "&ThisItem.DateTo,
    ThisItem.DateFrom     
)

 

 

 

Or if you add an empty string:

 

4.png

If(
    DateDiff(ThisItem.DateFrom,ThisItem.DateTo,Days) = 0,
    ThisItem.DateFrom&"",
    ThisItem.DateFrom&" - "&ThisItem.DateTo   
)
Categories:
  • Verified answer
    CarlosFigueira Profile Picture
    Microsoft Employee on at

    Thank you for reporting this issue!

     

    The issue is that there are two different types of data in the true_value and else_value for the If function: a Date value and a string. If you convert the date to a string, then this scenario should work:

    If(
     DateDiff(ThisItem.DateFrom,ThisItem.DateTo,Days) = 0,
     Text(ThisItem.DateFrom),
     ThisItem.DateFrom & " - " & ThisItem.DateTo
    )

    So you can use this workaround for now, while the fix doesn't get released.

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

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 409 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 328

#3
WarrenBelz Profile Picture

WarrenBelz 252 Most Valuable Professional

Last 30 days Overall leaderboard