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

ayekoto's avatar

diffForHumans for future date question

Hi everyone, was wondering if I can use diffFirHumans() for future date i.e

33mins from now

0 likes
2 replies
mstnorris's avatar

Yep. See http://carbon.nesbot.com/docs/#api-humandiff

// The most typical usage is for comments
// The instance is the date the comment was created and its being compared to default now()
echo Carbon::now()->subDays(5)->diffForHumans();               // 5 days ago

echo Carbon::now()->diffForHumans(Carbon::now()->subYear());   // 1 year after

$dt = Carbon::createFromDate(2011, 8, 1);

echo $dt->diffForHumans($dt->copy()->addMonth());              // 1 month before
echo $dt->diffForHumans($dt->copy()->subMonth());              // 1 month after

echo Carbon::now()->addSeconds(5)->diffForHumans();            // 5 seconds from now

echo Carbon::now()->subDays(24)->diffForHumans();              // 3 weeks ago
echo Carbon::now()->subDays(24)->diffForHumans(null, true);    // 3 weeks
ayekoto's avatar

Yes it worked and I did use it.

Thanks, Will mark your answer correct when am in system, can't do it from my phone

1 like

Please or to participate in this conversation.