Easy way to convert datetime value in Laravel
If you’re working with dates in Laravel, chances are you’ll need to convert them to another format at some point.
For instance, you might need to display a date in a human-friendly format like “July 1, 2020” or convert it to a different timezone.
The good news is that Laravel makes date conversion a breeze with its built-in Carbon class. In this blog post, we’ll take a look at how to use Carbon to convert dates in Laravel.
Let’s say we have a timestamp in the following format:
2020–07–01 00:00:00
We can convert this to a human-friendly format using the Carbon::parse() method:
$date = Carbon::parse(‘2020–07–01 00:00:00’);echo $date->toDateString(); // outputs “July 1, 2020”
We can also convert this timestamp to a different timezone using the Carbon::
Related Stories: