A simple PHP API extension for DateTime
open sourceMITself-hostablefree
Carbon is the standard date and time library for PHP, extending PHP's DateTime with a friendlier API. It adds and subtracts intervals with methods like addDay() and subWeek(), compares dates, converts between time zones, and formats dates for humans ("2 minutes ago", "next Friday") in hundreds of languages and regional formats. It offers immutable date objects so operations return new instances without side effects, plus CarbonInterval and CarbonPeriod for durations and ranges. Laravel has it built in, and it's MIT licensed.
Problems it solves
- show dates in PHP as "2 days ago" or "in 3 hours"
- add or subtract days, weeks or months from a date in PHP without manual arithmetic
- convert dates between time zones in a PHP app
- format dates in many languages and locales in PHP
- compare dates and check whether a date is a weekend in PHP
- work with dates in PHP without mutating the original object
Features
- extends PHP DateTime
- human-readable differences (diffForHumans)
- immutable date instances
- date arithmetic: add and subtract intervals
- time zone conversion
- localization in hundreds of languages with isoFormat
- date comparisons and helpers such as isWeekend and age
- CarbonInterval and CarbonPeriod