John Davidson

php - I want my date format to be in the form 09:54:24

0 comments
Message:


This is my controller


public function spTimeOnline(ServiceProvider $provider)
{
$serviceProviders = DB::select('select sp.fname,sp.lname,sp.location,sp.area, sp.phone_number,sp.profile_picture, (select count(*) from trips where driver_id = sp.id and ended is not null) as totalTrips,(select count(*) from trips where driver_id = sp.id and ended >= CURRENT_DATE ()) as tripsToday,(SELECT SUM(TIMESTAMPDIFF(SECOND,connected,disconnected)) from s_p_socket_connections where driver_id=sp.id) as time_spent,(SELECT SUM(TIMESTAMPDIFF(SECOND,connected,disconnected)) from s_p_socket_connections where driver_id=sp.id and connected >= CURRENT_DATE ()) as time_spent_today ,(select
case
when isnull(connected)
then false
when isnull(disconnected)
then true
else false
end
from s_p_socket_connections where driver_id=sp.id order by connected desc limit 1) as online from service_providers sp order by time_spent_today desc');

return view('time_online', compact('serviceProviders'));
}


And this is my blade file.


<td>{{$provider->time_spent ? \Carbon\CarbonInterval::second($provider->time_spent)->cascade()->forHumans(true):0}}</td>


it gives me the result in the format 9h 54m 24s but i want it in 09:54:24



My Answer:
is not null and started_at >= DATE_SUB(NOW(), INTERVAL 1 HOUR)) as tripsLastHour from service_providers sp where sp.status = 1');

foreach ($serviceProviders as $provider) {
$provider->timeOnline = date('H:i:s', strtotime($provider->timeOnline));
}

return view('service_providers', ['serviceProviders' => $serviceProviders]);
}

Rate this post

3 of 5 based on 2226 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us