laravel - How to calculate hour two date difference in php?
one text
Solution:
You have a laravel tag and therefore I suggest using Carbon.
Example:
$dateOne = Carbon\Carbon::parse("19-01-2022 12:49:00");
$dateTwo = Carbon\Carbon::parse("19-01-2022 13:49:00");
$dateTwo->diffInHours($dateOne); //gives you 1
Notes:
You do not need to parse into Carbon if the column name is already mutated through $dates
array in the model. https://laravel.com/docs/5.5/eloquent-mutators#date-mutators
Carbon documentation for reference: https://carbon.nesbot.com/docs/
Hope this points you in the right direction.
Source