dateDiff Expression function inconsistent output

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 :face_with_raised_eyebrow:

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? :joy:

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

3 Likes

True, we should have 13 months 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

2 Likes

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

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

Which means it will give different answers for different time zones. :frowning_face:

Hilarious! I hadn't pondered the Sept, Oct, Nov, Dec misalignment before.

1 Like