Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

MimisK's avatar
Level 12

TimeField and 24H format?

Good morning.

Is there a way to have only the time in 24H format?

Tried some packages I found from searching, but nothing...

Is there finally a way to have a field only for time and in 24H format?

thnx

0 likes
6 replies
LaryAI's avatar
Level 58

Yes, there is a way to have a field only for time in 24-hour format in Laravel. You can achieve this by using the HTML5 input type "time" and specifying the step attribute as "1" to allow only hour and minute inputs.

Here's an example of how you can implement it in a Laravel blade template:

<input type="time" step="1" name="time" id="time" required>

This will render a time input field that allows users to select the time in a 24-hour format. The "step" attribute ensures that only hour and minute inputs are allowed.

Remember to include the "required" attribute if you want to make the field mandatory.

I hope this helps! Let me know if you have any further questions.

Snapey's avatar

please provide more context

are you talking about in the database?

an input field?

php ?

javascript?

MimisK's avatar
Level 12

@Snapey

Sorry, I thought that was clear from the title.

I'm talking about input field.

MimisK's avatar
Level 12

@Snapey Hmmm I almost found a solution...

I have windows in 24h format, that's why it was strange that it didn't work.

I had Google Chrome in English. I just changed the language to English (UK) and the following worked:

Text::make('Soundcheck')->withMeta(['type' => 'time'])->displayUsing(function($value) {
			return $value ? Carbon::parse($value)->format('H:i') : '—';
}),

What theoretically should also work and doesn't is the following:

DateTime::make('Soundcheck')
				->displayUsing(fn ($value) => $value->format('H:i')),

About flatpickr. How can I use it? Do you mean to make a custom field?

thnx

Snapey's avatar

@MimisK Sorry, I don't have any experience with Nova and how you might introduce the javascript library

Please or to participate in this conversation.