Level 73
@dru Try this please:
$date = Carbon::createFromFormat('Y-m-d H:i:s', "2020-01-17 19:16:25", 'America/Santiago');
The format is wrong that you use for the time.
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have extracted from the database this date: "2020-01-17 19:16:25" which is a string. and when I try to convert it to find the difference in seconds to the actual time, I get this weird output:
$time = Carbon::createFromFormat('Y-m-d H:m:i',$time[0]->fecha_fin, 'America/Santiago'); -> this is the output date: 2021-04-17 19:25:00.0 America/Santiago (-04:00) for some reason.
keep in mind that in app.php I have configured this
'timezone' => 'America/Santiago',
how can I fix this to get the correct time:
dump($time->diffInDays(Carbon::now()));
@dru Try this please:
$date = Carbon::createFromFormat('Y-m-d H:i:s', "2020-01-17 19:16:25", 'America/Santiago');
The format is wrong that you use for the time.
Please or to participate in this conversation.