# dateDiff Expression function inconsistent output

**URL:** <https://forum.inductiveautomation.com/t/datediff-expression-function-inconsistent-output/97355>\
**Category:** Ignition\
**Created:** [October 16, 2024, 10:47pm UTC](https://forum.inductiveautomation.com/t/datediff-expression-function-inconsistent-output/97355 "2024-10-16T22:47:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [October 16, 2024, 10:47pm UTC](https://forum.inductiveautomation.com/t/datediff-expression-function-inconsistent-output/97355/1 "2024-10-16T22:47:02Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/9/39ac40ef16f07f5bb45ae6df2990fdd18275135e.png)

This output seems inconsistent.  
Minute and Day return decimal values, but month doesn't. Also, in that month example, the 24th Feb to the 12th March is _less than_ a month so it shouldn't be `1.0` 🤨

Not sure how this can be fixed though as people using the function will have had to have allowed for this in their code, and fixing it would cause it to break... `dateDiffFixed`? 😂

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [October 16, 2024, 11:37pm UTC](https://forum.inductiveautomation.com/t/datediff-expression-function-inconsistent-output/97355/2 "2024-10-16T23:37:15Z")

</div>

Months are variable length, its probably getting the difference in the recorded month number + number of years \* 12 or something like that. I guess it comes down to how you define a 'Month.'

Day and Minute are a bit more... solid? quantative? There aren't a variable number of minutes in a day\* (\* As far as we are concerned, we use the average of 86400 seconds/1440 minutes.)

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [October 17, 2024, 12:06am UTC](https://forum.inductiveautomation.com/t/datediff-expression-function-inconsistent-output/97355/3 "2024-10-17T00:06:46Z")

</div>

True, we should have 13 months [https://www.youtube.com/watch?app=desktop&v=vunESk53r5U&ab\_channel=DaveGorman](https://www.youtube.com/watch?app=desktop&v=vunESk53r5U&ab_channel=DaveGorman)

I think you're right though; months _can't_ have a decimal value due to that fact, as it would have a different fractional meaning for different months which could be confusing

---

<div class="post-metadata">

**Author:** ![KathyApplebaum](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kathyapplebaum/32/7261_2.png) [@KathyApplebaum](https://forum.inductiveautomation.com/u/KathyApplebaum)\
**Post date:** [October 17, 2024, 3:14pm UTC](https://forum.inductiveautomation.com/t/datediff-expression-function-inconsistent-output/97355/4 "2024-10-17T15:14:28Z")

</div>

Yes, this is pretty much exactly it, with year and month being extracted from Java's date methods:

```python
if (calUnit == Calendar.MONTH) {
    diff = (year2 - year1) * 12;
    diff += month2 - month1;
}
```

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [October 17, 2024, 3:16pm UTC](https://forum.inductiveautomation.com/t/datediff-expression-function-inconsistent-output/97355/5 "2024-10-17T15:16:58Z")

</div>

> [@KathyApplebaum](#):
>
> with year and month being extracted from Java's date methods:

Which means it will give different answers for different time zones. ☹

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [October 21, 2024, 1:59pm UTC](https://forum.inductiveautomation.com/t/datediff-expression-function-inconsistent-output/97355/6 "2024-10-21T13:59:07Z")

</div>

> [@nminchin](#):
>
> [we should have 13 months](https://www.youtube.com/watch?app=desktop&v=vunESk53r5U&ab_channel=DaveGorman)

Hilarious! I hadn't pondered the _Sept, Oct, Nov, Dec_ misalignment before.
