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

Ligonsker's avatar

Time validation between two time inputs

Hello,

Is it possible to validate and compare between 2 time inputs using the available rules, or I will have to have custom rule in this case?

I have 2 time inputs - start and end. They are in the format HH:mm and I need the end date to be greater than the start date.

Is there a combination I can have with the available rules to do that, or I should just create a custom rule?

Thanks

0 likes
6 replies
Ligonsker's avatar

@martinbean thanks, I just checked and the date doesn't work for strings of time like 11:10 for example.

Update: my mistake, you meant date_format, let me try

Ligonsker's avatar

@martinbean Update: From some reason the input time string is not matching the format. I tried both HH:MM and HH:mm, when I dd the $request->start_time for example, the string is "11:22" yet it does not match

Update #2: It seem to work with H:i

Ligonsker's avatar

@PovilasKorop could be, but I also wanna make sure the time is valid HH:mm. In this case I am trying to use the rule suggested by @martinbean, or, since it's a simple string I might do it with regex

1 like

Please or to participate in this conversation.