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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Date Difference functi...
Power Apps
Unanswered

Date Difference function not working fine in powerapps for days

(1) ShareShare
ReportReport
Posted on by 531
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:
I have the same question (0)
  • Suggested answer
    WarrenBelz Profile Picture
    153,034 Most Valuable Professional on at
    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   
  • Iantaylor2050 Profile Picture
    531 on at
    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?
     
  • WarrenBelz Profile Picture
    153,034 Most Valuable Professional on at
    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   
  • WarrenBelz Profile Picture
    153,034 Most Valuable Professional on at
    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   
  • Iantaylor2050 Profile Picture
    531 on at
     
    My current datetime is 15 July 2025 18:43 and enddatetime is 17 July 2025 18:00.
     
    The app shows something like below which is wrong. Why does it show HRS in negative?
     
    Shouldn't this be 01 DAYS, 23 HRS, 17 MINS? 
     
  • WarrenBelz Profile Picture
    153,034 Most Valuable Professional on at
    Works in the vast majority of cases - you have found a glitch where the start and end hour is the same. 
  • Power Platform 1919 Profile Picture
    1,890 on at
    Hi @Iantaylor2050
    can you please try this formula once,
    With(
        { totalSecs: DateDiff(varStartDT, varEndDT, TimeUnit.Seconds) },
        With(
            {
                days:    RoundDown(totalSecs / 86400, 0),
                hours:   RoundDown(Mod(totalSecs, 86400) / 3600, 0),
                minutes: RoundDown(Mod(totalSecs, 3600) / 60, 0),
                seconds: Mod(totalSecs, 60)
            },
            days & " days, " &
            hours & " hours, " &
            minutes & " minutes, and " &
            seconds & " seconds"
        )
    )
    
    
    Calculation Demo:

    Please give the mentioned solution a try and let me know whether it works for you.
    If it solves your issue, feel free to mark this thread as answered.
    Please make sure to like the response!
    Thanks!
    - Hemanth Sai

  • WarrenBelz Profile Picture
    153,034 Most Valuable Professional on at
    I had a similar exercise some time back based on minutes and got some very dodgy minute totals for the difference, particularly as the period grew in size. I did some testing on what you posted (changed to minutes as below to test my earlier experience) and it seems to work fine on a dozen or so examples over short and long periods.
    With(
       {
          totalMins: DateDiff(
             YurStartDateTime,
             YourEndDateTime,
             TimeUnit.Minutes
          )
       },
       With(
          {
             days: RoundDown(
                totalMins / 1440,
                0
             ),
             hours: RoundDown(
                Mod(
                   totalMins,
                   1440
                ) / 60,
                0
             ),
             minutes: RoundDown(
                Mod(
                   totalMins,
                   60
                ),
                0
             )
          },
          days & " days, " & hours & " hours, " & minutes & " minutes"
       )
    )
     
  • Power Platform 1919 Profile Picture
    1,890 on at
    Hi @Iantaylor2050, Just checking in to see if my previous answer hit the mark or if there’s anything else I can help you with.

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard