To convert a timestamp to a readable date and time format using Carbon in PHP, you can follow these steps:
composer require nesbot/carbon
use Carbon\Carbon;
$timestamp = 1597294800; // Replace with your timestamp
$carbon = Carbon::createFromTimestamp($timestamp);
format()
method:$formattedDateTime = $carbon->format('Y-m-d H:i:s');
The format parameter ('Y-m-d H:i:s') can be modified according to your requirements. Here are some common format options:
That's it! Now $formattedDateTime
will contain the timestamp converted to the desired readable format.