In a Laravel application I have some columns that are of type 'time' in my MySQL database. I am casting these time columns in my model using Carbon like so:
public function getStartDateAttribute()
{
return Carbon::createFromFormat('H:i:s', $this->attributes['start_time]);
}
The issue is that Carbon automatically sets any unspecified fields (e.g. month, day, year) to the current date.
This creates an issue when comparing times.
Usually in order to compare Carbon objects you would do something like this:
$a->lte($b); // where $a and $b are carbon objects
However, this may not work if I fetched $a at 11:59pm and $b at 00:00am. It's a rare corner case I know, but this is how things get hacked.
Therefore my question is, what is the proper way with dealing and comparing time for the MySQL time column?
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2lbFNGl
via IFTTT
Aucun commentaire:
Enregistrer un commentaire