Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel Carbon cast datetime to set seconds to 00

If I have variables like this:

$arivalTime1 = '2020-06-05 15:52:27'
$arivalTime2 = '2020-06-05 15:52:55'

how can I convert these variables using Carbon to have the seconds displayed as 00:

$converted1 = 2020-06-05 15:52:00
$converted2 = 2020-06-05 15:52:00
like image 498
Mister Verleg Avatar asked Sep 20 '25 17:09

Mister Verleg


1 Answers

there is many ways to do it:

1- like Vladimir verleg 's answer:

$arivalTime1 = '2020-06-05 15:52:27'
Carbon::parse($arivalTime1)->format('Y-m-d H:i:00');

2- using startOfMinute() method:

Carbon::parse($time)->startOfMinute()->toDateTimeString();

3- using create method witch gave you more control:

$value=Carbon::parse($time);
$wantedValue=Carbon::create($value->year,$value->month,$value->day,$value->hour,$value->minute,0);
like image 109
OMR Avatar answered Sep 22 '25 10:09

OMR