← BACK
Laravel / Utilities

Customize Relative Timestamps with diffForHumans() Options

Punyapal Shah • • 1 min read
edit this tip →

Pass Carbon options to diffForHumans() to control syntax flags, short units, and multi-part granularity.

Carbon's diffForHumans() displays human-readable dates. You can customize output by passing syntax flags for short units, removing 'ago' suffixes, or showing multiple time parts.

use Illuminate\Support\Carbon;

$date = now()->subDays(3)->subHours(4);

// Default: '3 days ago'
echo $date->diffForHumans();

// Short units: '3d 4h ago'
echo $date->diffForHumans(['short' => true, 'parts' => 2]);

// Absolute (no 'ago'): '3 days'
echo $date->diffForHumans(['syntax' => Carbon::DIFF_ABSOLUTE]);
  • short option abbreviates time units ('3d 4h')
  • parts parameter displays precise multi-unit granularity
  • DIFF_ABSOLUTE syntax removes directional 'ago' or 'from now' suffixes

Related Tips

View all tips →
Laravel Utilities

Use Immutable Dates by Default in Laravel

Configure Laravel's Date facade to use CarbonImmutable by default, and automate migrating legacy Carbon calls with Rector.

READ >

// Got a tip in mind? Contributions are always welcome