Libraries & Packages

Carbon: Date and Time Handling in PHP

Carbon extends PHP date and time handling with a fluent API for parsing, formatting, comparing and modifying dates.

Overview

Carbon is a widely used PHP date and time library built around PHP date-time objects. It offers expressive methods for common operations such as adding intervals, comparing dates, formatting output and working with time zones.

Common use cases

Applications use date libraries for publication schedules, subscription periods, reporting windows, deadlines and human-readable date output. Carbon can make these operations easier to read than long chains of low-level date calculations.

Installation and usage

Install Carbon through Composer, then create date instances from known inputs. Prefer explicit time zones for user-facing or business-critical dates, and distinguish calendar dates from timestamps representing an exact instant.

Best practices

Avoid relying on the server's implicit default time zone. Validate input formats, test daylight-saving transitions where relevant and use immutable date objects when accidental mutation would create bugs.

Official resource

Carbon documentation

Share this page Help other developers discover this resource.