Support the ongoing development of Laravel.io →
posted 7 years ago
Database

Hi, As you probably can tell from the title of the thread, the question is about formatting time.

Currently, when I retrieve time from DB, it shows as something like this: 09:45:00 The last two digits are useless in my scenario and I would like it as 09:45

My DB Query looks like this

$userDays = Day::where('user_id', '=', $user->id)
            ->whereMonth('date', '=', $request->month)
            ->whereYear('date', '=', $request->year)
            ->orderBy('date', 'desc')
            ->get();

It will select the start and end column from DB and my migration looks like

$table->time('start')->format('H:i');
$table->time('end');->format('H:i');

However, when look in the database (manually), it's stored as 09:45:00.

So anything that would output the time as HH:MI would work. It can be in the migration or in the controller.

Any answers are greatly appreciated. Waleed :)

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.