When I use diffForHumans it show 1 hour ago. When it cross 24 hour and show 1 day ago then 2 day, 3 day, 1 week, 2 week. But i want to show 1 day and 1/2/3/4 hour ago. then 2 day 1/2/3/4 hour ago.
I have been using laravel 5.7
You can use longAbsoluteDiffForHumans() or longRelativeDiffForHumans(), as an example given below :
$prev = Carbon::create(2018, 2, 26, 4, 29, 43);
$now = Carbon::now();
$diff = $prev->longAbsoluteDiffForHumans($now, 6);
return $diff; // 2 years 4 months 2 weeks 2 days 11 hours 5 minutes
See the official documentation here
{{ $data->created_at->longAbsoluteDiffForHumans(6) }} use longAbsoluteDiffForHumans(6) instead of diffForHumans()$submitdate = date('Y-m-d, H:m:s', strtotime($submit->created_at)); $diff = \Carbon\Carbon::create($submitdate); $now = \Carbon\Carbon::now(); $res = $diff->longAbsoluteresForHumans($now, 6); return $res;It is work with day count.
@php($diffInDays = \Carbon\Carbon::parse($user->created_at)->diffInDays())
@php($showDiff = \Carbon\Carbon::parse($user->created_at)->diffForHumans())
@if($diffInDays > 0)
@php($showDiff .= ', '.\Carbon\Carbon::parse($user->created_at)->addDays($diffInDays)->diffInHours().' Hours')
@endif
{{$showDiff}}
my answer is not better than the above answers, but below code worded for me as i customized the time column in the database.
date('H', strtotime($time_column))
it's a php function, and you can change the format I mean the 'H' the first argument in date() function to the format that best suit your app.
Carbon::parse($time_column)->hour
Carbon::parse($time_column)->daythis depends the value of the $time_column