The `Carbon` class for dates and times is a part of Laravel by default, but there's also a less-known class, `CarbonPeriod`. It can help generate the ARRAY of datetimes, often useful for report tables and calendars. In this tutorial, let's look at the 7 most practical examples of `CarbonPeriod`.
Under the hood, Laravel uses the Carbon library for many datetime operations. By default, every created_at/updated_at field in every Model is casted to Carbon objects, so you may write `$user->created_at->diffForHumans()`. But there are many more possibilities to that method, let's explore them.
We all use Carbon library to manage date and time, right? But who has actually read full documentation of what functions it has? In addition to well-known ones like now() or format(), Carbon has a lot more useful stuff. Let's take a look.
In Laravel, there's a convenient way to transform date/time DB fields to Carbon objects automatically. In fact, there are two ways, let me tell you about both.
When working with dates and times, we use awesome Carbon class, right? And there's a lot of small things in it which we might not even know. I will give you one example today.
Quite often the logic of our applications rely on the current time. For example, if it's weekend, or if it's past midday or something. We usually use Carbon::now() to check the time - but what if it's morning now, and we need to test if it's 5 PM already? Do we really need to wait till evening to test the function? No. Carbon has a trick for that.