Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Marcolino922's avatar

Many days are left until a date with "Carbon" expires

Hi, I tried but I couldn't get it to show how many days are left until a date with "Carbon" expires.

I have a hypothetical creation date: $created_at = ***

I would like to know how many days to the current date, today.

0 likes
1 reply
MichalOravec's avatar
Level 75
$created_at = Carbon::parse('2020-05-05');

$numberOfDays = now()->diffInDays($created_at);

// or

$numberOfDays = now()->diffInDays($created_at, false);

The 2nd parameter again is optional and indicates if you want the return value to be the absolute value or a relative value that might have a - (negative) sign if the passed in date is less than the current instance. This will default to true, return the absolute value.

Docs: https://carbon.nesbot.com/docs/#api-difference

Please or to participate in this conversation.