Carbon dates

Contents
Now
Parse input
Add and diff
Format output

Now

Carbon is the date library Laravel uses for every timestamp. The now method returns the current moment, and toDateTimeString prints it in database friendly form with no extra setup.

use Carbon\Carbon; echo Carbon::now()->toDateTimeString();

Parse input

User input arrives as plain text, so parse turns it into a real date object. It understands common formats out of the box and complains loudly about text that holds no date.

use Carbon\Carbon; $party = Carbon::parse("2026-12-31 20:00"); echo $party->toDateTimeString();

Add and diff

Dates support simple math through add and sub methods for days, months, and years. The diff family measures the gap between two moments in the unit you ask for, which fits countdowns and deadlines.

use Carbon\Carbon; $deadline = Carbon::now()->addDays(7); echo $deadline->toDateTimeString(); echo Carbon::now()->diffInDays($deadline);

Format output

The format method prints any part of a date with classic date codes. Pick a short code set for pages and keep the full timestamp for logs and exports.

use Carbon\Carbon; echo Carbon::now()->format("Y-m-d"); echo Carbon::parse("2026-10-06")->format("d.m.Y");

Next: Pagination

Article author: Arthur Isaev

Related articles
Development with PHP
What is Laravel and where it runs
Install Laravel
Your first route
Controllers
Blade basics
Blade advanced
Migrations
Eloquent models
Relationships
Query builder
Seeders and factories
Validation
Auth intro
Hand-rolled login
Middleware
Service container
Config and env
Artisan commands
Events and listeners
Queues
Mail
Cache
Sessions in Laravel
CSRF
Hashing
Sanctum tokens
API resources
Gates and policies
Notifications
Scheduler
Filesystem
Localization
Testing
HTTP tests
Collections
Carbon dates
Pagination
File uploads
Eloquent advanced
Transactions and locks
Deployment
Debugbar and dd
Broadcasting
Full-text search
Capstone: blog
Capstone: JSON API
Capstone: shop cart
Performance: kill N+1
Modern Laravel tour
Hero roadmap: the whole course on one page

Search this site

Channel @aofeed Chat @aofeedchat

Contacts and cooperation:
I recommend our hosting beget.com
Write to info@aredel.com if you:
1. Want to write an article for our site or translate an article into your native language.
2. Want to place thematically relevant ads on the site.
3. Ads on my site pass maximum censorship. If you see an ad block unsuitable for school-age children, shocking or misleading - please contact us by e-mail
4. Found a mistake, inaccuracy, bug, etc. on the site. ... .......
5. Articles can be shared on social media by clicking a network icon: