cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Owizardo
Level: Powered On

DateDiff in hours not accurate

Hello,

 

Found a weird problem, it seems like the DateDiff is not always accurate. For example look at this formula:

 

DateDiff(
    DateTimeValue("2019-05-23 10:25"),
    DateTimeValue("2019-05-23 16:00"), Hours
)

I would expect 5 hours but it gives 6 hours.

 

Example of accurate calculator:

https://www.timeanddate.com/date/durationresult.html?m1=5&d1=24&y1=2019&m2=5&d2=24&y2=2019&h1=10&i1=...

 

Anyone know if theres anything I can do about this? Meantime im gonna have to recode my application to use minutes :(.

 

1 ACCEPTED SOLUTION

Accepted Solutions
BrianR
Level 10

Re: DateDiff in hours not accurate

Does seem odd, initially I thought that it was just rounding, so changing your 10:25 to something like 10:35 would result in 5 instead, though this appears to NOT be the case (both return 6).  

But what you can do, as suggested, it to use Minutes:

DateDiff(
    DateTimeValue("2019-05-23 10:25"),
    DateTimeValue("2019-05-23 16:00"), Minutes
) / 60

which will return 5.58333333 in this case.  Or if you want just the "5":

RoundDown( DateDiff(
    DateTimeValue("2019-05-23 10:25"),
    DateTimeValue("2019-05-23 16:00"), Minutes
) / 60, 0 )


I do tend to agree though that DateDiff() in your example seems to be returning the WRONG answer - either have it return the full fractional "answer" (including taking minutes and seconds into account), or else round that down to have 5.  

But looks like its ONLY looking at the Hours part, and ignoring minutes and seconds, so my workaround SHOULD work (or to be more accurate use Seconds and / 3600).  🙂

View solution in original post

4 REPLIES 4
BrianR
Level 10

Re: DateDiff in hours not accurate

Does seem odd, initially I thought that it was just rounding, so changing your 10:25 to something like 10:35 would result in 5 instead, though this appears to NOT be the case (both return 6).  

But what you can do, as suggested, it to use Minutes:

DateDiff(
    DateTimeValue("2019-05-23 10:25"),
    DateTimeValue("2019-05-23 16:00"), Minutes
) / 60

which will return 5.58333333 in this case.  Or if you want just the "5":

RoundDown( DateDiff(
    DateTimeValue("2019-05-23 10:25"),
    DateTimeValue("2019-05-23 16:00"), Minutes
) / 60, 0 )


I do tend to agree though that DateDiff() in your example seems to be returning the WRONG answer - either have it return the full fractional "answer" (including taking minutes and seconds into account), or else round that down to have 5.  

But looks like its ONLY looking at the Hours part, and ignoring minutes and seconds, so my workaround SHOULD work (or to be more accurate use Seconds and / 3600).  🙂

View solution in original post

Highlighted
Super User
Super User

Re: DateDiff in hours not accurate

How about using this:

DateDiff(DateTimeValue(Time1), DateTimeValue(Time2)) * 24 + Hour(DateTimeValue(Time1) -   Hour(DateTimeValue(Time2))

Owizardo
Level: Powered On

Re: DateDiff in hours not accurate

Not quite sure I understand this formula but it it returns me 10 hours...

Super User
Super User

Re: DateDiff in hours not accurate

@BrianR's Rounddown formula should get you what you want.

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors
Users Online
Currently online: 340 members 6,754 guests
Please welcome our newest community members: