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

adnanerlansyah403's avatar

How to min input datetime-local with carbon

Hello everyone, I have a problem about minimalize the value from input datetime-local. So I want to previous date is disabled when the time has passed. I have tried code like this

Carbon\Carbon::now()->format('Y-m-d') . 'T' . Carbon\Carbon::now()->format('h:m:s') 

It's working in validation max input, but for min isn't and gets an error like this.

Please enter a valid value. The two nearest values are 04/10/2022 11:59:21 AM and 04/11/2022 12:00:21 PM

So how can I do for achieve this?

0 likes
4 replies
Snapey's avatar

can't answer with no context

by the way, you can create an iso8601 date like this

Carbon\Carbon::now()->format('Y-m-d\Th:i:s')
2 likes
adnanerlansyah403's avatar

@Snapey

<div class="form-group">
      <label for="expiry_date">Coupon Expire</label>
      <input type="datetime-local" class="form-control" min="{{ Carbon\Carbon::now()->format('Y-m-d\Th:i:s') }}" 
      name="expiry_date" placeholder="Enter Coupon Expire">        				
</div>

That's my code.So i want to disabled previous date in input datelocal-time with carbon, it's work but when i submit the form. i get an error validation input like this :

Please enter a valid value. The two nearest values are 04/10/2022 11:59:21 AM and 04/11/2022 12:00:21 PM
kokoshneta's avatar

So I want to previous date is disabled when the time has passed.

What does that mean? What is “previous date”? What time?

Without a clearer description of what it is you actually want to do, it’s very difficult to help you…

Please or to participate in this conversation.