I would like differences between two date results in Years and days not month
I have tried as below
$date1 = new DateTime("2023-01-01");
$date2 = new DateTime("2024-04-10");
$difference = date_diff($date1, $date2);
$years = $difference->y;
$months = $difference->m;
$days = $difference->d;
echo "$years Years";
echo "<br />";
echo "$months month";
echo "<br />";
echo "$days days";
and got result as
1 Years 3 month 9 days
I need the result as
1 Years 101 days
Could any one help on this.
I tried many ways but no one worked
Finaly I did it. I got my expeted result by below code
$date1 = new DateTime("2023-01-01");
$date2 = new DateTime("2024-04-10");
$difference = date_diff($date1, $date2);
$years = $difference->y;
// Calculate total days without including the years
$date1_copy = clone $date1;
$date1_copy->modify("+$years years");
$daysDifference = ($date1_copy->diff($date2)->days)+1;
echo "$years Years";
echo "<br />";
echo "$daysDifference Days";