cancel
Showing results for
Did you mean:
Helper III

## 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
Kudo Kingpin

## 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
Kudo Kingpin

## 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))

Helper III

## Re: DateDiff in hours not accurate

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

Highlighted
Super User

## Re: DateDiff in hours not accurate

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

Announcements

#### MBAS Gallery 2020

Watch Microsoft Business Applications Summit sessions on-demand.

#### New Ranks and Rank Icons released on April 21!

The time has come: We are finally able to share more details on the brand-new ranks coming to the Power Apps Community!

#### Power Platform 2020 release wave 1 plan

Features releasing from April 2020 through September 2020

Top Solution Authors
Top Kudoed Authors
Users online (7,093)