Sorry, this video is only available to Pro accounts.

Upgrade your account to get access to all content.

PHP DateTime with Carbon

Created on October 5th, 2016

Using DateTime in PHP can sometimes be a hassle. Luckily enough there is an awesome PHP library that we can use called Carbon. Carbon allows us to easily manipulate dates using PHP.

Now something as easy as getting yesterday's date in a nicely formatted string can be as easy as this:

<?php

$yesterday = Carbon::yesterday()->toFormattedDateString();
echo $yesterday; // Oct 4, 2016

If you had been working with javascript in the past and you are familiar with moment.js, you may have been wondering to yourself... "I wish dealing with DateTime in PHP was as easy as that", well now it is. Carbon is definitely a library you will want to include in all your PHP applications and if you are using Laravel you'll have the convenience of using this package out of the box :)

Comments (0)