I found some examples when searching, but couldn't find an example to show how many years are in-between unix timestamps.
I tried the following code:
$bought = $row['purchase_date'];
$sold = $row['sold_date'];
$duration = ($bought - $sold);
$years_owned = date("Y", $duration);
echo $years_owned;
Though I only got the echo result of the current year of 2023. The timestamps are from 2018 through 2023 so I was expecting the echo to show 4.7 years (when rounded up) based on the exact timestamps which are:
bought = 1539320400 sold = 1687179600
I then tried this and it worked but it will only give me 5 years as a result and not the exact amount of years in decimal format:
$bought = date("Y",$row['purchase_date']);
$sold = date("Y",$row['sold_date']);
$duration = ($bought - $sold);
$years_owned = $duration;
echo $years_owned;
Which gave me 5 years but not the 4.7 I was looking for and I expected that result. I would like to get the exact number of how long I owned something before selling it. A lot of search results are asking about seconds or days and I need the years.