Carbon Introduction
Carbon is the date/time library Laravel uses everywhere for readable date handling.
Syntax
\Illuminate\Support\Carbon::parse('2026-01-01');Carbon extends PHP's DateTime with a fluent, human-friendly API. Laravel returns Carbon instances from now(), model timestamps and more.
Create one with the now() helper or \Illuminate\Support\Carbon::parse().
Example
Loading editor…
Press Run to execute the code.
When to use it
- A subscription service compares now() to a user's trial_ends_at field using Carbon's isBefore() to gate access to premium features.
- A booking platform stores appointment times as UTC in the database and uses Carbon to convert them to the user's local timezone for display.
- A cron job creates Carbon instances from raw database timestamp strings to perform date arithmetic before deciding which records to archive.
More examples
Create Carbon instances
Shows four ways to instantiate a Carbon object: current time, today at midnight, parsing a string, and from a Unix timestamp.
use Carbon\Carbon;
$now = Carbon::now(); // current moment
$today = Carbon::today(); // today at midnight
$date = Carbon::parse('2025-06-01'); // from string
$stamp = Carbon::createFromTimestamp(1740000000); // from Unix tsUse now() in an Eloquent query
Eloquent casts timestamp columns to Carbon automatically, enabling direct method calls like isFuture() on model attributes.
use Illuminate\Support\Facades\DB;
// Eloquent models return Carbon for timestamp columns automatically
$subscriptions = Subscription::where('expires_at', '>', now())
->where('trial_ends_at', '<=', now())
->get();
// Check a model attribute
if ($user->trial_ends_at->isFuture()) {
// still on trial
}Timezone conversion for display
Parses a UTC timestamp then converts it to the user's local timezone before formatting it for display.
use Carbon\Carbon;
$utc = Carbon::parse('2025-03-14 18:00:00', 'UTC');
$local = $utc->setTimezone('America/New_York');
echo $local->format('D d M Y H:i T');
// => 'Fri 14 Mar 2025 14:00 EDT'
Discussion