cancel
Showing results for
Did you mean:
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
Highlighted
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).  :-)

4 REPLIES 4
Highlighted
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).  :-)

Super User

## Re: DateDiff in hours not accurate

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

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

## Re: DateDiff in hours not accurate

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

Announcements

#### Microsoft Business Applications Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

#### Watch Sessions On Demand!

Continue your learning in our online communities.

#### Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

#### Power Platform World Tour

Coming to a city near you

#### PowerApps Community User Group Member Badge

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

#### Join PowerApps User Group!!

Connect, share, and learn with your peers year-round

Top Kudoed Authors
Users Online
Currently online: 153 members 3,109 guests
Recent signins: