Forum Discussion
Wrong result using DATESDIFF
- 2 years ago
when you make datesdiff by year, it gets the difference between the year only not the whole date, so it takes that what's the different between 2023 to 2024,it's 1, because 23+1 = 24
Thanks for your answer Idrissshatila
But then, what about the date 2023-11-08? Shouldn't it be 0 as well? Or is it not basing the calculation on a year meaning 365 days, but on going from 2023 to 2024, for example.
when you make datesdiff by year, it gets the difference between the year only not the whole date, so it takes that what's the different between 2023 to 2024,it's 1, because 23+1 = 24
- Victormar2 years agoHelper V
Got it, thanks. I guess then the best solution is to do the difference in days and divide by 365? My idea is to calculate a natural year from the start date.
- Idrissshatila2 years agoSuper User
Hello Victormar ,
you can specify the interval as you want in the datesdiff function.
examples:
( "Year", DATEDIFF ( StartDate, EndDate, YEAR ) ),
( "Quarter", DATEDIFF ( StartDate, EndDate, QUARTER ) ),
( "Month", DATEDIFF ( StartDate, EndDate, MONTH ) ),
( "Week", DATEDIFF ( StartDate, EndDate, WEEK ) ),
( "Day", DATEDIFF ( StartDate, EndDate, DAY )
check this https://learn.microsoft.com/en-us/dax/datediff-function-dax
- Victormar2 years agoHelper V
thanks!