xxxxxxxxxx
// laravel time
{{ Carbon\Carbon::parse($item->created_at)->diffForHumans() }}
// time
{{ dd(Carbon\Carbon::now()) }}
xxxxxxxxxx
use Illuminate\Support\Carbon;
$current = Carbon::now()->format('YmdHms'); //it will give current date and time
xxxxxxxxxx
use Carbon\Carbon;
$date = Carbon::now();
// Format the date using Carbon
$formattedDate = $date->format('Y-m-d H:i:s');
// Output the formatted date
echo $formattedDate;
xxxxxxxxxx
1. First parse the created_at field as Carbon object.
$createdAt = Carbon::parse($item['created_at']);
2.Then you can use
$suborder['payment_date'] = $createdAt->format('M d Y');
xxxxxxxxxx
use Carbon\Carbon;
$date = Carbon::now();
$formattedDate = $date->format('Y-m-d H:i:s');
echo $formattedDate;
xxxxxxxxxx
use Illuminate\Support\Carbon;
$datetime = "yourDateTime"; // example: "2022.12.13" or "2022-12-13T10:00:00.000Z" or etc.
$carbon = Carbon::parse($datetime); // returned new Carbon class by given any formatted date(time)
xxxxxxxxxx
$now = Carbon::now();
echo $now; // 2020-03-22 17:45:58
echo "\n";
$today = Carbon::today();
echo $today; // 2020-03-22 00:00:00
echo "\n";
$tomorrow = Carbon::tomorrow('Europe/London');
echo $tomorrow; // 2020-03-23 00:00:00
echo "\n";
$yesterday = Carbon::yesterday();
echo $yesterday; // 2020-03-21 00:00:00
xxxxxxxxxx
//Syntax example : create new dateTime from chosen format
$start_time = Carbon::createFromFormat('H:i', '08:00');
// Outputs 'YYYY-MM-DD 08:00:00'
//Syntax example : parse existing dateTime into chosen format
Carbon::parse($start_time)->form
// Outputs '08:00'