Question:I have two dates by which I am calculating no of years/months. For below 2 dates I am getting output as
0as it should return
Here is my query
Please suggest what I am doing wrong here
returns the largest integer equal to or less than n
so there is no way it can return 0.4. The
ceilfunction is the similar. Neither takes an argument allowing retention of decimal places. And you don’t want to
roundit, as in your example that would give 0.5, not 0.4.
Fortunately you can use
trunc, which does have a decimal-place argument:
The TRUNC (number) function returns n1 truncated to n2 decimal places.
So you want
trunc(<difference between dates>, 1)to get retain 1 decimal place.
truncbehaves essentially as you would want
floor(n1, n2)to if that existed; there is no equivalent for
ceil, but you can work around that. The same method can be applied here too, but isn’t needed; I’ve included it in this db<>fiddle for fun.
If you have better answer, please add a comment about this, thank you!