jeudi 2 avril 2020

Laravel carbon get time until expires

I have a product which expires after a set number of days. I'm trying to display to the user how many days they have left until it expires. I can't seem to get it to display the correct number of days remaining I have all the parts but the output is incorrect. I'm hoping its not a limitation with carbon that I'm running into...

Here is my full code;

$order->created_at->addDays($order->service->duration)->subDays($order->created_at->addDays($order->service->duration)->diffInDays(Carbon\Carbon::now()))->diffForHumans()

Break down;

Work out the end/expiry date -


Work out how many days used so far -


So it should be the end/expiry date subtract the days already used e.g expires in 5 days and its been 3 days 5 - 3 = 2 days left (full query again)

$order->created_at->addDays($order->service->duration)->subDays($order->created_at->addDays($order->service->duration)->diffInDays(Carbon\Carbon::now()))->diffForHumans()

The value returned is 23 hours from now when it should be 200+ days



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire