Good day everyone, I'm working on showing progress by percentage when to reach the expiry date based on the current date.
I have this code now
// $value->expiry_date = "2021-02-21"
$date_now = Carbon::now();
$date_of_expiry = Carbon::parse($value->expiry_date);
$diff = $date_of_expiry ->diffInDays($date_now);
$wl = 45 - $diff;
$total = 45; // total days of trial
$percent = $wl / $total * 100;
dd($percent);
I have the output below, which is I'm thinking wrong because the date now is the beginning of the trial, it should be 0 and tomorrow it will change, that is what I'm expecting.
2.22222222
also when I try to add 44 days on $date_now it's already 0 on date difference, is it correct or I'm just confused on the Carbon dates.
$date_now = Carbon::now()->addDays(44);
$date_of_expiry = Carbon::parse($value->expiry_date);
$diff = $date_of_expiry ->diffInDays($date_now);
dd($diff)
output
0
Working code snippet for demo password: 12345678
https://laravelplayground.com/#/snippets/fbe6b25b-a6e4-4f45-9ab3-cb51dc744b4b