Easier date and time handling with Carbon

Laravel bundles Carbon (https://github.com/briannesbitt/Carbon), which extends and augments PHP's native DateTime object with more expressive methods. Laravel uses it mainly to provide more expressive methods on the date and time properties (created_at, updated_at, and deleted_at) of an Eloquent object. However, since the library is already there, it would be a shame not to use it elsewhere in the code of your application.

Instantiating Carbon objects

Carbon objects are meant to be instantiated like normal DateTime objects. They do, however, support a handful of more expressive methods:

  • Carbon objects can be instantiated using the default constructor that will use the current date and time as follows:
    • $now ...

Get Laravel 5 Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.