Reputation: 1187
I want to format my date to be like this yyyyMMddHHmmss
Here is my currentcode
$now = Carbon::now()->toString();
$format='yyyyMMddHHmmss';
//$parsed = Carbon::parse($now);
$formatted = Carbon::parse($now);
//$x = strtotime($now);
dd($formatted);
I got a date like this
Carbon\Carbon @1580189543 {#223 ▼
date: 2020-01-28 13:32:23.0 +08:00
}
If I modify my code like this
$formatted = Carbon::parse($now,$format);
dd($formatted);
It says Unknown or bad timezone (yyyyMMddHHmmss)
I just want my date to become like this 20200128 133223
Does anyone know how to do it?
Upvotes: 0
Views: 2958
Reputation: 3712
Your desire format is like
Carbon::now()->format('yymd his')
For details https://www.php.net/manual/en/class.datetime.php
Upvotes: 0