I am trying to return the number of years between 2 dates as a decimal with greater precision.
For example:
If the difference is 1 year and 1 month and 15 days, I'd like to return a value of 1.15 or something like that. Ultimately, in this example, I'd like to show the difference is 1 year 1 month and 15 day difference shown in a decimal form.
I am able to get the decimal value to return, but I am unsure how to get the tenth and hundred decimal places to show properly. I'm sure I need to do some math to get that to show properly. Currently, my code just returns zero on the right side of the decimal place.
select
*,
cast((cast(begin_date as date) - cast(end_date as date) YEAR) as decimal (3,2)) AS year_diff
from
x
Again, the expected results would be a value of 1.15 between 2 values that are 1 year, 1 month and 15 days apart. Currently I am only returning 1.00.