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
Hello Victormar ,
the result is correct, Datediff function calculate the difference between two dates as per the interval you choose, so in your case you selected by year, so it shows tthe difference between the start date and today by year,
so what it is doing is that : start date 2020-01-06 and today which is 2024-02-21, the difference in years is zero because we are in the same year.
whereas the difference 2023-11-08 and today 2024-02-21 is 1 because the difference between 2023 and 2024 is 1.
- Victormar2 years agoHelper V
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.
- Idrissshatila2 years agoSuper User
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.