0
I’m having trouble fixing the time to decrease it in php.
My idea take the time that comes from the database and decrease with the current time and bring the rest , however.
code I’m using as an example:
$results =DB::select("SELECT HoraCriacao FROM partidas WHERE (Aceitou=2) ORDER by Id desc LIMIT 1 ");
foreach($results as $row){
$Hroin=$row->HoraCriacao;
}
$Hroin = strtotime($Hroin);
$Hroin=date('H:i:s',$Hroin);
$Hroin=date_create($Hroin);
$Horat= date('H:i:s');
$Horat = explode(":", $Horat);
date_sub($Hroin, date_interval_create_from_date_string($Horat[0].' hours'));
date_sub($Hroin, date_interval_create_from_date_string($Horat[1].' minute'));
date_sub($Hroin, date_interval_create_from_date_string($Horat[2].' second'));
$Hroin=date_format($Hroin, 'H:i:s');
$Hroin = explode(":", $Hroin);
$banco=[
"mod" => "3",
"cron" => "$Hroin[0]:$Hroin[1]:$Hroin[2]"
];
return response()->json($banco);
Friend please try to explain better, because your code is very confused and I could not understand your need.
– Kayo Bruno
In the Database there is an event time when it was created example :
$horain="14:40:00" ;
then I want to decrease with the current time$horaat="14:50:00";
then I want to catch the difference– Cyber Hacker
Are you wearing Laravel? That one
DB::select
is familiar– Wallace Maxters
@Kayobruno, then he’d have to go back to the rest like 00:10:00
– Cyber Hacker
@Wallacemaxters, yes I know very little of the Aravel
– Cyber Hacker
Missed to tag then, huh
– Wallace Maxters
I put down an answer on how to calculate the difference between dates. See if it helps you with something.
– Kayo Bruno
Dude, I always try to use https://carbon.nesbot.com/docs/ for date manipulation in Laravel
– Luiz Gustavo Costa Ceolin