PHPackages                             top/carbon - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. top/carbon

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

top/carbon
==========

A simple API extension for DateTime.

1.21.0(10y ago)082MITPHPPHP &gt;=5.3.0

Since Sep 11Pushed 9y ago1 watchersCompare

[ Source](https://github.com/maxboom/Carbon)[ Packagist](https://packagist.org/packages/top/carbon)[ Docs](http://carbon.nesbot.com)[ RSS](/packages/top-carbon/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (25)Used By (0)

Carbon
======

[](#carbon)

[![Latest Stable Version](https://camo.githubusercontent.com/ccb0052e49ee9f020df907533c80b5bc753265f1a9fc3f3c40109a51fef70dde/68747470733a2f2f706f7365722e707567782e6f72672f6e6573626f742f636172626f6e2f762f737461626c652e706e67)](https://packagist.org/packages/nesbot/carbon)[![Total Downloads](https://camo.githubusercontent.com/7f4f01c66e8ce309d10e904e6adeb3403e5f0e267c156f82aa3109edfaed6062/68747470733a2f2f706f7365722e707567782e6f72672f6e6573626f742f636172626f6e2f646f776e6c6f6164732e706e67)](https://packagist.org/packages/nesbot/carbon)[![Build Status](https://camo.githubusercontent.com/1793310af078bab29277e07900b4d3cc03aaf3f401942b1fb54f88388cb73317/68747470733a2f2f7472617669732d63692e6f72672f627269616e6e6573626974742f436172626f6e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/briannesbitt/Carbon)[![StyleCI](https://camo.githubusercontent.com/3d99dc9527e4779e073bc846a69a7017aec8bb8219c87a0e5d03aed6ee46363a/68747470733a2f2f7374796c6563692e696f2f7265706f732f353732343939302f736869656c643f7374796c653d666c6174)](https://styleci.io/repos/5724990)[![codecov.io](https://camo.githubusercontent.com/61128bcfd85a93ebe3983fa8bf9e24fcc8f9b53bc4d8a845dd05b602e9eb077a/68747470733a2f2f636f6465636f762e696f2f6769746875622f627269616e6e6573626974742f436172626f6e2f636f7665726167652e7376673f6272616e63683d6d6173746572)](https://codecov.io/github/briannesbitt/Carbon?branch=master)

A simple PHP API extension for DateTime.

```
use Carbon\Carbon;

printf("Right now is %s", Carbon::now()->toDateTimeString());
printf("Right now in Vancouver is %s", Carbon::now('America/Vancouver'));  //implicit __toString()
$tomorrow = Carbon::now()->addDay();
$lastWeek = Carbon::now()->subWeek();
$nextSummerOlympics = Carbon::createFromDate(2012)->addYears(4);

$officialDate = Carbon::now()->toRfc2822String();

$howOldAmI = Carbon::createFromDate(1975, 5, 21)->age;

$noonTodayLondonTime = Carbon::createFromTime(12, 0, 0, 'Europe/London');

$worldWillEnd = Carbon::createFromDate(2012, 12, 21, 'GMT');

// Don't really want to die so mock now
Carbon::setTestNow(Carbon::createFromDate(2000, 1, 1));

// comparisons are always done in UTC
if (Carbon::now()->gte($worldWillEnd)) {
    die();
}

// Phew! Return to normal behaviour
Carbon::setTestNow();

if (Carbon::now()->isWeekend()) {
    echo 'Party!';
}
echo Carbon::now()->subMinutes(2)->diffForHumans(); // '2 minutes ago'

// ... but also does 'from now', 'after' and 'before'
// rolling up to seconds, minutes, hours, days, months, years

$daysSinceEpoch = Carbon::createFromTimestamp(0)->diffInDays();
```

Installation
------------

[](#installation)

### With Composer

[](#with-composer)

```
$ composer require nesbot/carbon

```

```
{
    "require": {
        "nesbot/carbon": "~1.21"
    }
}
```

```
