This article covers how to manage date/time easily in Laravel and PHP with Carbon. Basically, Carbon is a package that helps us to deal with date/time in Laravel and PHP in a much easier and systematic manner.
Working with date and time in PHP is not the easiest or most clear of tasks. We have to deal with strtotime, formatting issues, lots of calculations, and more.
Carbon provides some nice functionality to deal with dates in PHP such as:
1. Dealing with timezones
2. Getting current time easily
3. Converting a datetime into something readable
4. Parse an English phrase into datetime (first day of January 2016)
5. Add and Subtract dates (+ 2 weeks, -6 months)
6. Semantic way of dealing with dates
Carbon is already included in Laravel so there's no need to go and add it with Composer.
Whenever we need to use Carbon, we can import it like so:
After importing you can do a lot with this great package.