I'm using Carbon to manipulate dates on my platform, and I have no idea how to solve this.
public function theTurnIs($tipe){
$fecha_actual = $this->getTodayDate('notFormat');
$parse_date = Carbon::parse($fecha_actual);
$hora = $parse_date->hour;
if ($tipe == "hospital") {
if($hora > 19 || $hora < 7){
return "morning";
}elseif ($hora > 13 || $hora < 18) {
return "late";
}
}
}
The problem I have is that I need to compare hours and a half, but Carbon::parse
it only returns the hour or the minute... and what I need is to compare something
if($hora > '19:30' || $hora < '07:30'){
return "morning";
}
and that the variable $hora
has an hour with minutes... to be able to compare them... any ideas?
In this case, the only thing you would need would be to use the function
format
that has carbon, in the following way:$hora = $parse_date->format('H:i');
In this way you transform it to hour and minutes, and it is available to make the comparison.