Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Suggested answer

Date Difference function not working fine in powerapps for days

(1) ShareShare
ReportReport
Posted on by 502
I have built a shopping portal in powerapps where my shopping ends on 07 July 2025 06:00PM. My current local time is 06 July 01:00AM. 
 
I have written a code below to indicate when my shopping ends as per screenshot below. I notice that Days indicated in red is wrong. It should return 0 days instead of 1. May i know where i am going wrong?
 
 
On Timer End code
Set(
    varmins,
    Text(
        Mod(
            DateDiff(
                Now(),
                LookUp(
                    ShoppingDB,
                    Status = true,
                    Date
                ),
                "Minutes"
            ),
            60
        ),
        "[$-en-US]00"
    ) & " "
);Set(
    varhrs,
    Text(
        Mod(
            DateDiff(
                Now(),
                LookUp(
                    ShoppingDB,
                    Status = true,
                    Date
                ),
                "Hours"
            ),
            24
        ),
        "[$-en-US]00"
    ) & " "
);Set(
    vardays,
    Text(
        Mod(
            DateDiff(
                Now(),
                LookUp(
                    ShoppingDB,
                    Status = true,
                    Date
                ),
                "Days"
            ),
            365
        ),
        "[$-en-US]00"
    ) & " "
)
 
Categories:
  • WarrenBelz Profile Picture
    148,625 Most Valuable Professional on at
    Date Difference function not working fine in powerapps for days
    A quick follow-up to see if you received the answer you were looking for or if you need further assistance.

    Please click Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it a Like.
    MVP (Business Applications)    Visit my blog Practical Power Apps    LinkedIn    Buy me a coffee
  • WarrenBelz Profile Picture
    148,625 Most Valuable Professional on at
    Date Difference function not working fine in powerapps for days
    Sorry, grabbed that from a test app - did it some time ago and must have been before I refined it. I have updated the post with the prod item.
     
    Please click Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it a Like.
    MVP (Business Applications)    Visit my blog Practical Power Apps    LinkedIn    Buy me a coffee
  • Iantaylor2050 Profile Picture
    502 on at
    Date Difference function not working fine in powerapps for days
    Hi @WarrenBelz
     
    It still doesnt work. My current local time is 06 July 17:46 and shopping ends on 07 July 17:00. 
     
    Hence the correct datetime should show as 00 days, 23 hrs, 14 mins. 
     
    But its displaying something wrong. May i know why?
     
  • Suggested answer
    WarrenBelz Profile Picture
    148,625 Most Valuable Professional on at
    Date Difference function not working fine in powerapps for days
    This is out of a similar exercise I do on an app - it works fine for me (obviously different start and end date/times)
    With(
       {
          _Start: Now(),
          _End: LookUp(
              ShoppingDB,
              Status
          ).Date
       },
       UpdateContext(
          {
             vardays: Text(
                RoundDown(
                   DateDiff(
                      _Start,
                      _End,
                      TimeUnit.Days
                   ),
                   0
                ) - If(
                   Hour(_Start) > Hour(_End),
                   1
                ),
                "[$-en-US]00"
             ) & " ",
             varhours: Text(
                RoundDown(
                   Mod(
                      DateDiff(
                         _Start,
                         _End,
                         TimeUnit.Hours
                      ),
                      24
                   ),
                   0
                ) - If(
                   Minute(_Start) > Minute(_End),
                   1
                ),
                "[$-en-US]00"
             ) & " ",
             varmins: Text(
                RoundDown(
                   Mod(
                      DateDiff(
                         _Start,
                         _End,
                         TimeUnit.Minutes
                      ),
                      60
                   ),
                   0
                ),
                "[$-en-US]00"
             ) & " "
          }
       )
    )
     
    Please click Does this answer your question if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it a Like.
    MVP (Business Applications)    Visit my blog Practical Power Apps    LinkedIn    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

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 791 Most Valuable Professional

#2
MS.Ragavendar Profile Picture

MS.Ragavendar 410

#3
mmbr1606 Profile Picture

mmbr1606 275 Super User 2025 Season 1